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

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

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境