2011-07-12 11 views
0

グラフAPIを使用して壁紙フィードを取得するためにFacebook APIを使用しています。グラフAPIは、プロファイルフィードを表示しない

<?php 
    require_once('facebook.php'); 

// Create our Application instance (replace this with your appId and secret). 
$facebook = new Facebook(array(
    'appId' => '188687744521977', 
    'secret' => 'c2c3692845602812f473436d1da95014', 
    'cookie' => true 
)); 

// Get User ID 
$user = $facebook->getUser(); 

// We may or may not have this data based on whether the user is logged in. 
// If we have a $user id here, it means we know the user is logged into 
// Facebook, but we don't know if the access token is valid. An access 
// token is invalid if the user logged out of Facebook. 

if($user) 
{ 
    try 
    { 
//   Proceed knowing you have a logged in user who's authenticated. 
     $access_token = $_SESSION['fb_188687744521977_access_token']; 
      $user_profile = $facebook->api('/me'); 
      $likes = $facebook->api('/me?fields=feed,likes'); 
     $friends = $facebook->api('/me/friends'); 
     $feed = 'https://graph.facebook.com/me/feed? access_token='.$access_token.''; 
    } catch (FacebookApiException $e) 
    { 
     error_log($e); 
     $user = null; 
    } 
} 

// Login or logout url will be needed depending on current user state. 
if($user) 
{ 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else 
{ 
    $loginUrl = $facebook->getLoginUrl(); 
} 

// Save the user's info as variables 
$full_name = $user_profile['name']; 
$first_name = $user_profile['first_name']; 
$last_name = $user_profile['last_name']; 

$relationship = $user_profile['relationship_status']; 
$partner_id = $user_profile['significant_other_id']; 

$id = $user_profile['id']; 
$link = $user_profile['link']; 

function get_url($url) 
{ 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 5); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
     $tmp = curl_exec($ch); 
     curl_close($ch); 
     return $tmp; 
} 

$wall = get_url($feed); 
print_r(json_decode($wall, true)); 
?> 

ただし、空の配列が表示されます。助言がありますか?

答えて

0

アクセストークンを処理するためのより良いソリューションを見つけようとしてください。これはどこに設定しています$_SESSION['fb_..._access_token']?誰が188687744521977は常にログインしているユーザーのユーザーIDですか?フィードURLにスペースがあるのはなぜですか?

最初に行うべきことは、json_decode()var_dump()$wallを削除することです。私はあなたのアクセストークンが有効ではないと思っています、おそらく401 Unauthorizedまたは403 Forbiddenレスポンスも得られますか?

+0

いいえ、実際は401または403メッセージが表示されません。番号はアプリケーションではなくユーザーのIDです。その数は静的です。 – Lance

関連する問題