Twitter API OAuth PHP post_tweet.php


Twitter API OAuth PHP post_tweet.php

我无法获得以下任何结果来从php发布推文。我已经在twitter上注册了我的应用程序,并获得了我的凭据。我制作了一个名为access_tokens.php的页面,并下载了一个称为tmhOAuth.php的OAuth库。我正遵循一个示例教程,但似乎什么都没有出现——有什么可以提供的帮助吗?

access_tokens.php

<?php
$consumer_key = 'xx';
$consumer_secret = 'xx';
$user_token = 'xx';
$user_secret = 'xx';
//xx is the replacement for my actual values
?>

post_tweet.php

<?php
//Load the app's keys into memory
require 'app_tokens.php';
//Load the tmOAuth library
require 'tmhOAuth.php';
//Create an OAuth connection to the Twitter API
$connection = new tmhOAut(array(
                            'consumer_key'   =>     $consumer_key,
                            'consumer_secret'=>     $consumer_secret,
                            'user_token'     =>     $user_token,
                            'user_secret'    =>     $user_secret
                            ));
//Send a tweet
$code = $connection -> request('POST',
    $connection -> url('1.1/statuses/update'),
    array('status' => 'Hello Twitter'));
//A response code of 200 is a success
if ($code == 200){
    print "Tweet sent";
}
else{
    print "Error:$code";
}                               
?>

查找OAuth库是否有支持,因为几个月前我尝试过做同样的事情,我发现一些帖子告诉我,自三月以来,它就不能再使用了。无论如何,我不确定它是否是那个库,但如果你编写与twitter相关的代码,你必须意识到他们经常更改API。