TijsVerkoyen\Twitter\Twitter::directMessagesNew PHP Method

directMessagesNew() public method

Sends a new direct message to the specified user from the authenticating user. Requires both the user and text parameters and must be a POST. Returns the sent message in the requested format if successful.
public directMessagesNew ( string[optional] $userId = null, string[optional] $screenName = null, string $text ) : array
$userId string[optional]
$screenName string[optional]
$text string The text of your direct message. Be sure to URL encode as necessary, and keep the message under 140 characters.
return array
    public function directMessagesNew($userId = null, $screenName = null, $text)
    {
        // validate
        if ($userId == null && $screenName == null) {
            throw new Exception('One of user_id or screen_name are required.');
        }
        // build parameters
        $parameters['text'] = (string) $text;
        if ($userId != null) {
            $parameters['user_id'] = (string) $userId;
        }
        if ($screenName != null) {
            $parameters['screen_name'] = (string) $screenName;
        }
        // make the call
        return $this->doCall('direct_messages/new.json', $parameters, true, 'POST');
    }

Usage Example

Beispiel #1
0
 /**
  * Tests Twitter->directMessagesNew
  */
 public function testDirectMessagesNew()
 {
     $response = $this->twitter->directMessagesNew(null, 'tijs_dev', 'Running the tests.. 私のさえずりを設定する ' . time());
     $this->isDirectMessage($response);
     $this->twitter->directMessagesDestroy($response['id']);
 }
Twitter