简体   繁体   English

尝试使用Abraham Williams Twitter API库完全陷入困境

[英]Completely stuck trying to use Abraham Williams Twitter API libraries

I'm working through Sam's Teach Yourself Twitter API.. In Hour 8, there are simple instructions of setting up the consumer key, consumer secret (I already had a different php program using these succesfully) and using Abraham Williams libraries. 我正在通过Sam的Teach Yourself Twitter API进行工作。在第8小时中,有简单的说明来设置消费者密钥,消费者秘密(我已经成功地使用它们使用了另一个php程序)和使用Abraham Williams库。 I plugged the key,secret into config.php, used the define('OAUTH_CALLBACK', 'http://localhost/callback.php'); 我将密钥,秘密插入config.php,使用define('OAUTH_CALLBACK','http://localhost/callback.php'); with localhost and created a tinyurl for it (the work around if localhost doesnt work. Get the sign in to Twitter screen and then it goes to the redirect page that says: 使用localhost并为其创建了一个tinyurl(如果localhost不起作用,请变通。获得登录Twitter屏幕的信息,然后转到显示以下内容的重定向页面:

“Could not connect to Twitter. “无法连接到Twitter。 Refresh the page or try again later.” 刷新页面或稍后重试。”

I'm completely dead in the water here. 我完全死在这里的水中。 Once I get this working, I'll be off and running, but I'm completely stuck. 一旦开始工作,我就可以运行了,但我完全被卡住了。 Any help would be appreciated. 任何帮助,将不胜感激。

(In reponse to your questions:) (针对您的问题:)

They have a config.php file where they say to put in the KEY and SECRET, which I've done: 他们有一个config.php文件,他们说要在其中放入KEY和SECRET,我已经完成了:

define('CONSUMER_KEY', 'KEY');
define('CONSUMER_SECRET', 'SECRET');
define('OAUTH_CALLBACK', 'http://localhost:8888/abeoauth/connect.php');

They book says to run index.php. 他们预定运行index.php。 Here's code from that: 这是以下代码:

/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');

/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) ||     empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,     $access_token['oauth_token'], $access_token['oauth_token_secret']);

/* If method is set change API call made. Test is called by default. */
$content = $connection->get('account/verify_credentials');

Starting at index.php, like the book says, it does redirect to the "connect.php" page so it's as if I've put nothing in for the KEY variables at all.. 正如书中所说,从index.php开始,它的确会重定向到“ connect.php”页面,就好像我根本没有在KEY变量中放任何东西一样。

Ok guys. 好了朋友们。 Looks like it didn't like the "twitter application"(credentials) that I'd created for a different script (that worked btw). 看起来好像不喜欢我为另一个脚本创建的“ twitter应用程序”(凭证)(该脚本有效)。 I had to create a new one just for this book example. 我只需要为本书的示例创建一个新的示例。

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

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