简体   繁体   English

麻烦使用PHP Twitter库发送推文

[英]Trouble using PHP Twitter libraries to send tweet

To preface, I don't know much about PHP. 作为序言,我对PHP知之甚少。 However, I'm not sure that this is a PHP issue but maybe more of an issue with me understanding the libraries for connecting to Twitter. 但是,我不确定这是一个PHP问题,但可能更多的是我理解连接到Twitter的库的问题。

I followed the tutorial here http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/ which uses Matt Harris' twitter library. 我按照这里的教程http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/使用了Matt Harris的推特库。 I didn't change anything except the keys which I obtained from twitter. 除了我从twitter获得的钥匙外,我没有改变任何东西。

When I run the following code I get an unauthorized error code 401: 当我运行以下代码时,我得到一个未经授权的错误代码401:

  $tweet_text = 'Hello Twitter';
  print "Posting...\n";
  $result = post_tweet($tweet_text);
  print "Response code: " . $result . "\n";

 function post_tweet($tweet_text) {

 require_once('tmhoauth/tmhOAuth.php');

 $connection = new tmhOAuth(array(
'consumer_key' => '******',
'consumer_secret' => '******',
'user_token' => '******',
'user_secret' => '******',
)); 

// Make the API call
$connection->request('POST', 
$connection->url('1/statuses/update'), 
array('status' => $tweet_text));

return $connection->response['code'];
 }
?>

As I said previously, I am using the keys provided by twitter. 正如我之前所说,我使用的是twitter提供的密钥。

Could someong help me with trying to use the above library to test the twitter credientail validator at https://api.twitter.com/1/account/verify_credentials.json ? 我可以帮助我尝试使用上面的库在https://api.twitter.com/1/account/verify_credentials.json上测试twitter credientail验证器吗?

I also tried using the following example with the TwitterOAuth library from this SO post Using basic oauth to send a tweet : 我也尝试使用以下示例与此SO帖子中的TwitterOAuth库使用基本oauth发送推文

<?php
require_once('twitteroauth.php');
$connection = new TwitterOAuth('app consumer key', 'app consumer secret', 'my access     token', 'my access token secret');
$connection->post('statuses/update', array('status' => 'text to be tweeted'));

It didn't work as well; 它不起作用; but it did forward the page to the author's github page!?!? 但它确实将页面转发给了作者的github页面!?!?

Thanks for any help you can provide! 感谢您的任何帮助,您可以提供!

If you are sure the keys are correct I would advise you check the application settings within twitter to ensure that write mode is enabled. 如果您确定密钥是正确的,我建议您检查一下twitter中的应用程序设置,以确保启用了写入模式。

Under the applications settings make sure the application type access is set to 在应用程序设置下,确保将应用程序类型访问权限设置为

Read, Write and Access direct messages 读取,写入和访问直接消息

(Or at least Read/Write) (或至少读/写)

Then perhaps try generating the access token again? 那么也许尝试再次生成访问令牌?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM