【问题标题】:Twitter API OAuth PHP post_tweet.phpTwitter API OAuth PHP post_tweet.php
【发布时间】:2013-06-28 02:59:16
【问题描述】:

从 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";
}                               

?>

【问题讨论】:

    标签: php api twitter oauth


    【解决方案1】:

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

    【讨论】:

    • IDK 如果支持该 OAuth 库,但我确实让它与另一个库一起使用。现在,只要我能显示时间线而不是空白就好了。是的,编码!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多