J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 800 forks source link

Is it possible to send a reply to a mention with TwitterAPIExchange? #240

Closed cbielich closed 7 years ago

cbielich commented 7 years ago

I can post a reply to a status on my own timeline fine with https://api.twitter.com/1.1/statuses/update.json but I am suspecting that I need a different POST URL to reply to a mention. I went through all the ones listed at https://dev.twitter.com/rest/reference but I cant find one that seems to work for what I need. I have been told it's possible to do it, I just don't know how.

require_once('TwitterAPIExchange.php');

$settings = array(
    'oauth_access_token' => $twitter_accesstoken,
    'oauth_access_token_secret' => $twitter_accesstokensecret,
    'consumer_key' => $twitter_apikey,
    'consumer_secret' => $twitter_apisecret
);

$url = 'https://api.twitter.com/1.1/statuses/update.json';
$postfields = array(
    'in_reply_to_status_id' => $in_reply_to_status_id, 
    'status' => $status
);

$requestMethod = 'POST';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setPostfields($postfields)
    ->buildOauth($url, $requestMethod)
    ->performRequest();
trampish commented 7 years ago

Per the API docs, make sure you include the handle of the user who posted the tweet you're replying to in your status/tweet – even if it yourself. Doesn't seem to matter where it goes in your tweet (beginning/end) as long as it is recognized as a valid handle. Hope this helps!

J7mbo commented 7 years ago

Closing this as no response. If this is not the case and is still an issue please feel free to re-open / create a new issue.