2012-10-14 202 views
0

我快要放弃。大约一周我正在尝试最简单的事情,通过Facebook进行身份验证。每次我authenticatiom时间(通过Facebook登录URL)的getUser()和API( '我' )返回我空。Facebook验证失败

为什么?

代码:

$facebook = new Facebook(array(
    'appId' => '306597542762982', 
    'secret' => '88XXXXXX7f1', 
)); 
$user = $facebook->getUser(); 

if ($user) { 
    try { 
    // Proceed knowing you have a logged in user who's authenticated. 
    $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
} 

if (!$user) { 

    $loginUrl = $facebook->getLoginUrl(array('scope'=>'user_actions.news,publish_stream,user_about_me,email,publish_actions')); 

    print $loginUrl; exit; 

} 

var_dump($facebook->api('me')); 

SOS。

编辑:POST:

$params = array (
    'article' => 'http://fb.raal.co.il/content/view/$id/$title', 
    'access_token' => $facebook->getAccessToken() 
); 



$out = $facebook->api('/me/news.reads','post', $params); 

var_dump($out); exit; 
+0

什么错误/消息你好吗? –

+0

为的getUser() - > INT(O),为API(“我”) - >致命错误:未捕获OAuthException:活性访问令牌必须用于查询当前用户的信息。抛出/home1/raalcoil/public_html/fb/lib/facebook/base_facebook.php上线1106 – WEBProject

回答

1

继续什么空指针引用较早,从用户ifaour:

Just check for the current Facebook user id $user and if it returned null then you need to reauthorize the user (or use the custom $_SESSION user id value - not recommended)

require 'facebook/src/facebook.php'; 

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

$user = $facebook->getUser(); 

$photo_details = array('message' => 'my place'); 
$file='photos/my.jpg'; //Example image file 
$photo_details['image'] = '@' . realpath($file); 

if ($user) { 
    try { 
    // We have a valid FB session, so we can use 'me' 
    $upload_photo = $facebook->api('/me/photos', 'post', $photo_details); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    } 
} 

// login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
// redirect to Facebook login to get a fresh user access_token 
    $loginUrl = $facebook->getLoginUrl(); 
    header('Location: ' . $loginUrl); 
} 

I've written a tutorial on how to upload a picture to the user's wall.

随着更多的信息,这是否帮助?还有我发现与此相关的,说明试图

$facebook->getAccessToken();

显然更多的信息,该呼叫可以给任何一个应用程序访问令牌或用户访问令牌。根据您使用访问令牌所做的操作,您需要适当的种类。

或者,你可能需要请求特定的权限你正在尝试做的,你可以找到here

+0

好,工作 - 但现在的动作后不会工作,我得到致命错误:未捕获的异常:无法检索URL数据。投入1106行的/home1/raalcoil/public_html/fb/lib/facebook/base_facebook.php – WEBProject