Facebook PHP SDK $uid = $facebook->getUser() always returns 0 [duplicate]

三世轮回 提交于 2019-12-04 17:14:55

In window.fbAsyncInit I have set cookie and oauth to true and this worked!

cookie:true,    
oauth : true.

Make sure that In your php you also have

cookie' => true.

That will enable the php code to integrare with the JS.

And you need to make sure the user has logged in with:

$loginUrl = $facebook->getLoginUrl(array( 'scope' => 'read_stream,etc..'));

The scope is defined by the permissions stated here

After that you should be able to do:

$user = $facebook->api("/me");

Which will get an array associated with the user, $user['id'] is probably the one you'll want to store as well as any other information like email address - be sure to request for email in the scope

Hope that solves the problem!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!