通过终端运行twitter php脚本

时间:2014-06-23 02:51:30

标签: php twitter terminal

我正在尝试访问Twitter帐户的信息,但我一直遇到此错误: 解析错误:在第33行的/Users/thegreenfrog/Desktop/twitter/tweet.php中解析错误,期待'')''

我似乎没有看到问题所在,所以我希望其他人做到了!

谢谢!

<?php

// Load the app's OAuth tokens into memory
require 'app_tokens.php';

// Load the tmhOAuth library
require 'tmhOAuth.php';

// Create an OAuth connection to the Twitter API
$connection = new tmhOAuth(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";
// }

//Get @justinbieber's account info
$connection->request('GET', $connection->url('1.1/users/show'), array('screen_name' => 'justinbieber’));
//Get the HTTP response code for the API request 

$response_code = $connection->response['code'];
// Convert the JSON response into an array
$response_data = json_decode($connection->response['response'],true);
// A response code of 200 is a success 

if ($response_code <> 200) {
print "Error: $response_code\n"; }
// Display the response array 
print_r($response_data);
?>

1 个答案:

答案 0 :(得分:3)

哥们,

您使用了错误的引号

'justinbieber’));

也是错误的艺术家。大声笑。开玩笑。

将其替换为:

$connection->request('GET', $connection->url('1.1/users/show'), array('screen_name' => 'justinbieber'));