我如何获得推特帖子?

时间:2015-06-15 13:55:39

标签: php twitter

我正在尝试按照本教程获取推特帖子: https://www.youtube.com/watch?v=tPrsVKudecs

关于这个在线没有很多教程,而且据我所知,twitters控制台不支持运行查询。

知道为什么会这样吗?

这是我在Chrome“网络”中获得的输出:

Remote Address:54.666.666.666:80
Request URL:http://666.com/yh/test/tweets_json.php
Request Method:GET
Status Code:500 Internal Server Error
Response Headers
view source
Connection:close
Content-Length:0
Content-Type:text/html
Date:Mon, 15 Jun 2015 13:51:40 GMT
Server:Apache/2.4.7 (Ubuntu)
X-Powered-By:PHP/5.5.9-1ubuntu4.5
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:666.com
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36

为什么会发生这种情况?

有更好的简单方法吗?

修改

tweets_json.php

<?php
require 'tmhOAuth.php'; // Get it from: https://github.com/themattharris/tmhOAuth

// Use the data from http://dev.twitter.com/apps to fill out this info
// notice the slight name difference in the last two items)

$connection = new tmhOAuth(array(
  'consumer_key' => '',
    'consumer_secret' => '',
    'user_token' => '', //access token
    'user_secret' => '' //access token secret
));

// set up parameters to pass
$parameters = array();

if ($_GET['count']) {
    $parameters['count'] = strip_tags($_GET['count']);
}

if ($_GET['screen_name']) {
    $parameters['screen_name'] = strip_tags($_GET['screen_name']);
}

if ($_GET['twitter_path']) { $twitter_path = $_GET['twitter_path']; }  else {
    $twitter_path = '1.1/statuses/user_timeline.json';
}

$http_code = $connection->request('GET', $connection->url($twitter_path), $parameters );

if ($http_code === 200) { // if everything's good
    $response = strip_tags($connection->response['response']);

    if ($_GET['callback']) { // if we ask for a jsonp callback function
        echo $_GET['callback'],'(', $response,');';
    } else {
        echo $response; 
    }
} else {
    echo "Error ID: ",$http_code, "<br>\n";
    echo "Error: ",$connection->response['error'], "<br>\n";
}

// You may have to download and copy http://curl.haxx.se/ca/cacert.pem

tmhOAuth.php:https://github.com/themattharris/tmhOAuth/blob/master/tmhOAuth.php

和这个pem键:http://curl.haxx.se/ca/cacert.pem

所有三个在同一个文件夹中

在教程中,它应该运行查询并获取json输出。

我得到一个空白页面。

0 个答案:

没有答案