doujia1988 2011-01-04 11:57
浏览 48
已采纳

Facebook图形api问题

iam using openid for login in my site, and upon successful login, i could get the user's email and other parameters like first name.

But for facebook, iam using facebook connect (Graph api) and after successful login, iam getting an access token. But using this token, iam not able to fetch the user's email. I end up with an error saying either invalid token or invalid redirect url.

  • 写回答

1条回答 默认 最新

  • dongtan1845 2011-01-04 16:28
    关注

    After you get your initial token, you must redirect the user to the login URL requesting the permissions you want, in this case, "email". The easiest way to implement this is using the PHP SDK provided by Facebook.

    If the user grants the permissions, you'll be able to query the graph api to get the email address (along with other basic information.) Once you have a valid working token and the user has authorized your application, the email address will be included $user_data.

    $facebook = new Facebook(array('appId'=>APP_ID, 'secret'=>APP_SECRET, 'cookie'=>true));
    
    try{
       $user_data = $facebook->api('/me'); 
    } catch (Exception $e){ 
       header('Location: ' . $facebook->getLoginUrl(array('perms'=>'email'));
       die();
    }
    
    print $user_data['email'];
    

    Be aware that the email address may be a proxy address and be much longer than a typical email address so allocate sufficient space in your storage system. For example, the address might look something like this: apps+2356396727.745.22667a3160x3d6wd2c1396c4efd7277b@proxymail.facebook.com

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序