开发者

PHP Twitter post using oAuth and 403 error

开发者 https://www.devze.com 2023-03-20 01:56 出处:网络
Im having an issue with posting to Twitter, using oAuth, and recieving a 403 error. Let me explain: Having done all the authentication and \'running\' this:

Im having an issue with posting to Twitter, using oAuth, and recieving a 403 error. Let me explain:

Having done all the authentication and 'running' this:

$message = "Some text";
$oauth->post('statuses/update', array("status" => $message));

The message appears on Twitter, I get a 200 response and all is well.

However when I try and use:

$message = $text;
$oauth->post('statuses/update', array("status" => $message));

Now $text is fetched from some XML, using SimpleXMLElement in PHP. I then use $text = $entry->summary; to store the string I want to tweet. Im already checking that the text is < 140 characters so I know the text is of the correct length.

However when running the code I get a 403 error.

Here is an example of the contents of $message, which contains $text from var_dump:

object(SimpleXMLElement)#8 (2) { ["@attributes"]=> array(1) { ["type"]=> string(4) "html" } [0]=> string(104) "Attempting a PHP script to tweet something when it features the hashtag #tweeted and is under 140 chars." } 

I thought it might be the # being in there that was causing the problem but I can confirm that I can tweet using the first example c开发者_JS百科ontaining a hash with no problems.

Do I need to encode or decode the string in some way before sending it on to Twitter? Im confused.


The problem is that you're trying to send an object $text as a string.

So anything that converts SimpleXmlElement object to string should work. I think even plain simple $message = (string)$text will do the trick.


$message = urldecode($text);

Problem solved.

0

精彩评论

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

关注公众号