0
<?php

function fetchUrl($url){

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_TIMEOUT, 20);

 $feedData = curl_exec($ch);
 curl_close($ch); 

 return $feedData;

}

$profile_id = "xxxxxxxxxxxxx";

//App Info, needed for Auth
$app_id = "xxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxx";

 $authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}");

$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/posts?{$authToken}");




$feedarray = json_decode($json_object);

echo $json_object;

foreach ( $feedarray->data as $feed_data )
{
    echo "<h2>{$feed_data->name}</h2><br />";
    echo "{$feed_data->message}<br /><br />";
}

  ?>

当我尝试使用我的详细信息(完全打开的页面)运行我的代码时,我得到一个输出

Warning: Invalid argument supplied for foreach() in /home/xxxxxxxxx/public_html/includes/footer.php on line 52

当我使用下面的代码时,它会打印 bool(false)。

$feedData = curl_exec($ch);
var_dump($feedData); die();

我发现 fetchUrl 不起作用,我尝试了许多不同的方法,但似乎都不起作用......

有任何想法吗?

4

0 回答 0