我使用 api twitter c 通过脚本工作:
var arrtweets = [];
var x;
//Function url formater
function url(searchTerm, numOfTweets){
result = 'http://catcoin.ru/twitter.php?q=' + searchTerm + '&count='+ numOfTweets;
return result;
}
// API Sendler
var get100Tweet = function(data) {
$.each(data.statuses, function(index, item) {
arrtweets.push(item.text);
});
x = Math.floor((Math.random() * 100) + 1);
y = arrtweets[x].toString();
$('#list').html(y);
};
function TweetRandom(name) {
document.getElementById("list").innerHTML = $.get(url(name,100),get100Tweet);
}
我需要获取用户的最新推文而不是 api 允许的搜索结果
<?php
$http_origin = $_SERVER['HTTP_ORIGIN'];
if ( strrpos($http_origin, "catcoin.ru") || strrpos($http_origin, "jsfiddle.net") ){
header("Access-Control-Allow-Origin: $http_origin");
}
header('Content-Type: application/json');
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?'.$_SERVER['QUERY_STRING'];
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$api_response = $twitter ->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
echo $api_response;
https://gist.github.com/anonymous/234284d3eb6817969d9e04e497f5ad4a
不幸的是,我没有找到如何在纯 php 中执行此操作,但我找到了一个接收此数据的库。
您还可以通过作曲家连接:
就我而言,调用是: