dongshao8125 2015-06-17 23:20
浏览 32

创建Facebook Canvas应用程序 - 在PHP SDK中登录和验证

Starting over... upgrading a 4-year-old Facebook Canvas App to the latest PHP SDK (4.0.23).

As I understand it, the flow is something like:

1) Facebook calls my app (mydomain.com/myApp)

2) I need to determine if this Facebook account has logged into my app already - looks like a signed_request comes across if not.

3) I create a FacebookRedirectLoginHelper with my app url (mydomain.com/myApp) and then generate a loginUrl. Then the user should click on that.

4) Facebook puts up a permission request, and if the user accepts, calls back to my app url. This time, instead of a signed_request, I get a code. At this point - do I create a FacebookRedirectLoginHelper again to process to get my session? Or, as the PHP SDK document suggests, do I create a FacebookCanvasLoginHelper?

4a) Reading the code for FacebookCanvasLoginHelper, it seems like I have to invoke $helper->instantiateSignedRequest($signedRequest) before I can use it, else there will be no signed request there. But the signed request I got the first time around does not have oauth data in it, so getSession() fails.

4b) If I use FacebookRedirectLoginHelper, I do get a session back, but there is no signed_request in it. So I can't get the userID. If I push the signed_request that I have into the FacebookSession object, still nothing because that initial signed_request doesn't have it.

What am I missing here? What I need is the Facebook UID of the account, that is stored locally to tell my app who is running it.

Help? Thoughts? I must be missing something, because other people have this working, right?

andy

  • 写回答

1条回答 默认 最新

  • dourun2990 2015-06-24 22:25
    关注

    Your last step (4a) is the correct one. The session you get doesn't have user information, it's just a session you'll have to use to call the API again and retrieve whatever you want. You can consider this as the equivalent of the access token, actually if you have an access token, you can even create a session object doing this:

    $session = new FacebookSession('access token here');
    

    Once you have your session object, you have to call the graph API to get the information you want:

    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    

    Everything is explained in the docs: https://developers.facebook.com/docs/php/gettingstarted/4.0.0

    I hope it helps.

    Edit: I've created a simple Facebook login example using PHP SDK: https://github.com/javierdelacueva/facebook-php-login-example please feel free to take a look

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序