开发者

Updating Twitter Status: Character Escaping and URLs

开发者 https://www.devze.com 2022-12-08 07:13 出处:网络
I pass text from a POST variable from a form on my site to Twitter and I save this message on my own site. When I view the entry on my site it is absoultly fine. However, in some cases when there is a

I pass text from a POST variable from a form on my site to Twitter and I save this message on my own site. When I view the entry on my site it is absoultly fine. However, in some cases when there is an apostrophe in the message twitter updates the status of a user but escapes the apostrophes and this can be seen on the users status!

This doesn't happen when I update my twitter status on the twitter site. So I am wondering is there a way I need to pass text to twitter?

I currently do this and I make use of this awesome Twitter class. http://github.com/jmathai/twitter-async/tree

$success = $twitterObj->post_statusesUpdate(array('status' => $_POST['message'].$URL.$key));

In addition, passing URLs to twitter use to automatically link the URL but now this just appears as text?

Has twitter made changes in the past month that would cause the above to happen? If not how can I overcome this?

Thanks all

EDIT

More Code:

function tweetit(){
    global $URL;
    global $key;

    include './twitter/EpiCurl.php';
    include './twitter/EpiOAuth.php';
    include './twitter/EpiTwitter.php';

    $consumer_key = 'hidden';
   开发者_C百科 $consumer_secret = 'hidden';

    $twitterObj = new EpiTwitter($consumer_key, $consumer_secret);

    $twitterObj->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

    $success = $twitterObj->post_statusesUpdate(array('status' =>  $_POST['message'].' '.$URL.$key));

    return $success->response['id']; 
}


Sounds like your php config has magic_quotes_gpc turned on, which automagically calls addslashes on all input (e.g., your POST values). I'd read up on addslashes/stripslashes in the php manual.


Are you using the latest version? Not sure what the problem is since one of the unit tests for the library puts in single quotes (among other random characters).

http://github.com/jmathai/twitter-async/blob/master/tests/EpiTwitterTest.php#L90


You can use htmlentities function for this.

$success = $twitterObj->post_statusesUpdate(array('status' => htmlentities($_POST['message']).$URL.$key));

Or htmlspecialchars:

$success = $twitterObj->post_statusesUpdate(array('status' => htmlspecialchars($_POST['message']).$URL.$key));


I had the same problem. Twitter behaves differently if called with www.twitter.com instead of twitter.com. This is a known bug.

http://code.google.com/p/twitter-api/issues/detail?id=890&can=1&q=www&colspec=ID%20Stars%20Type%20Status%20Priority%20Owner%20Summary%20Opened%20Modified%20Component


After you receive the post but before you send it off via the curl, remove slashes with stripslashes

urlencode(stripslashes($posted_status_update));
0

精彩评论

暂无评论...
验证码 换一张
取 消