0

I am using twitter-api-php. I am posting statuses and it works well. The only problem is, when the tweet starts with @username, its returning a blank page. I don't know whats wrong. This problem is not just with me, when googling about it, found another person with same query,

Here is the code I am using to post.

$settings = array(
    'oauth_access_token' => "ACCESS_TOKEN",
    'oauth_access_token_secret' => "ACCESS_TOKEN_SECRET",
    'consumer_key' => CONSUMER_KEY,
    'consumer_secret' => CONSUMER_SECRET
);

$url = "https://api.twitter.com/1.1/statuses/update.json";
$str = "@sourabh_bajaj this is a sample tweet";
$requestMethod = 'POST';

$twitter=new TwitterAPIExchange($settings);
echo $twitter->setPostfields(
    array(
        "trim_user" => 1,
        "status" => $str
    )
)->buildOauth($url, $requestMethod)->performRequest();

This works well if we remove @sourabh_bajaj from the start of the message.

  • It is far more likely that there are two people out there who have bugs in their code than the Twitter API has such a critical bug with no documentation or report on it. Post some of your code! – 2rs2ts Jul 5 '13 at 22:02
  • Added some code and explaination. – Sourabh Jul 5 '13 at 22:19
2

Your Exact Issue

You haven't gotten the latest version of the library you're using!

This commit on github shows the fix for your exact problem:

$array['status'] = sprintf("\0%s", $array['status']);

Basically, adding a blank space or a full stop is not how to fix this. I added a null character to the beginning, and all tweets (and @reply tweets - which won't work properly with full stops) now work great.

This is due to a limitation with cURL, and @ symbols at the beginning (cURL thinks you're trying to upload a file when you do this).

So, to reiterate:

Re-download TwitterAPIExchange.php, and keep checking out the changelog. You'll find this solves your issue.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.