0
我無法從twitter API訪問media_url。我知道它在媒體陣列中,我相信媒體陣列是在一個實體陣列中。我只是無法獲得正確的語法。我已經嘗試向用戶數組創建一個類似的數組,但這不起作用。我也嘗試製作一個像用戶數組一樣的實體數組,但是數組返回空。從twitter API訪問media_url
<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "XXX-XXXXXXXX",
'oauth_access_token_secret' => "XXXXXXXX",
'consumer_key' => "XXXXX",
'consumer_secret' => "XXXX"
);
/** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/
$url = 'https://api.twitter.com/1.1/blocks/create.json';
$requestMethod = 'GET';
/** POST fields required by the URL above. See relevant docs as above **/
$postfields = array(
'screen_name' => 'usernameToBlock',
'skip_status' => '1'
);
/** Perform a POST request and echo the response
e response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23blacklivesmatter';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$tweetData = json_decode($twitter->setGetField($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
echo $tweetData;
foreach($tweetData['statuses'] as $items)
{
$userArray = $items['user'];
$entitiesArray = $items['entities'];
$mediaArray = $entitiesArray['media'];
$date = new DateTime($items->created_at);
echo "<div class='tweet-div'><div class='float-left twitpic'><a target='_blank' href='http://www.twitter.com/" . $userArray['screen_name'] . "'><img class='twitter-pic' target='_blank' src='" . $userArray['profile_image_url'] . "'></a></div>";
echo "<a target='_blank' href='http://www.twitter.com/" . $userArray['screen_name'] . "'><span class='name bold'>" . $userArray['name'] . "</span> </br><span class='handle'>@" . $userArray['screen_name'] . "</span></a> <span class='font-small'>⋅ ";
echo $date->format('M jS') . "</span></br>";
echo $items['text'] . "</br></br>";
echo "<img target='_blank' src='http://" . $mediaArray['media_url'] . "'></br></br>";
echo $mediaArray['media_url'] . "";
echo "<span class='border'></span></div>";
}
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
?>