【问题标题】:posted status with php/curl to twitter not appearing使用 php/curl 向 Twitter 发布的状态未出现
【发布时间】:2013-11-05 18:51:03
【问题描述】:

我使用以下函数发布到 twitter,它返回一条成功消息,但该推文没有出现在 twitter 时间线上。请注意,该网站使用 WAMP 在我的本地主机上。 我启用了卷曲。

下面的函数:

         function Post_to_twitter($message){
     // Set username and password
         $username = 'myaccountusername';
         $password = 'mypass';
         // set the twitter API address
         $url = 'http://twitter.com/statuses/update.json';
         // setup a curl process
         $curl_handle = curl_init();
         // set the url of the curl process
         curl_setopt($curl_handle, CURLOPT_URL, "$url");
         // saves the return value as a string value instead of outputting to browser
         curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
         // to send data as $_POST fields as required by the twitter API
         curl_setopt($curl_handle, CURLOPT_POST, 1);
         // set the post fields
         curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
         // set the username and password for the connection
         curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
         // exectute the curl request and save output as $buffer variable
         $buffer = curl_exec($curl_handle);
         // close the curl connection
         curl_close($curl_handle);
         // decode json output into array
         $json_output = json_decode($buffer, true);
         $status = '' ;
         // check for success or failure
         if (isset($json_output['error'])) {
            // tweet not successful, display error
          $status = 'failed' ;
         }
         else {
         $status = 'succesful' ;
         }
         return $status ;
         }

         echo Post_to_twitter('Hello world');

【问题讨论】:

  • 有错误吗?此外,如果它是重复的推文,它可能不会显示。

标签: php json curl twitter


【解决方案1】:

Twitter 已更新其 API。现在需要通过 OAuth 进行身份验证。

您可以阅读有关 Twitter 身份验证的更多信息here

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 2021-11-27
    • 1970-01-01
    相关资源
    最近更新 更多