简体   繁体   English

使用facebook js sdk和php sdk

[英]using facebook js sdk and php sdk

I believe I have read almost all if not all the related posts, but I still can't find my answer. 我相信我已经阅读了几乎所有(即使不是全部)相关的帖子,但是我仍然找不到答案。

On client side I get the user to login and send user id and access token to server. 在客户端,我让用户登录并向服务器发送用户ID和访问令牌。 Then server use facebook->getUser() to check if the sent userid really belong to him, if so I add him to my database and register him. 然后服务器使用facebook->getUser()来检查发送的用户ID是否确实属于他,如果是的话,我将其添加到数据库中并进行注册。 similar to this question 类似于这个问题

Facebook Login: How to combine JavaScript with PHP SDK? Facebook登录:如何将JavaScript与PHP SDK结合?

except facebook->getUser() keep returning 0. I have look through A LOT of questions related to that too, but I just cant find my answer. 除了facebook->getUser()返回0。我也浏览了很多与此相关的问题,但我只是找不到答案。 No problem with client side though, user can log in and give authority, it generate the correct userid and a token. 客户端没问题,用户可以登录并授予权限,它会生成正确的用户ID和令牌。

I am currently using localhost to test everything. 我目前正在使用localhost测试所有内容。

php: 的PHP:

<?php
require 'facebook/src/facebook.php';

$uid = $_POST['userid'];
$token = $_POST['accessToken'];


$facebook = new Facebook(array(
  'appId'  => 'XXXXXXXXXXXXXXXXX',
  'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
));

// Get User ID
$user = $facebook->getUser();

if($user==$uid){
//codes here

My question is similar to the following posts but it didnt get any answer Facebook API: Login using JavaScript SDK then checking login state with PHP 我的问题类似于以下文章,但未得到任何答案Facebook API:使用JavaScript SDK登录,然后使用PHP检查登录状态

additional info: the reason why I want to use PHP sdk too is because, I dont want people to use someone else's fb userID to send request to my server 'pretending' to be another person 其他信息:我也想使用PHP sdk的原因是,我不希望人们使用别人的fb userID向我的服务器“假装”成为另一个人发送请求

You receive the FB Token from your FB Javascript SDK. 您从FB Javascript SDK收到FB令牌。 Are you setting the FB Token in PHP first with the one you received from Javascript? 您是否首先在PHP中使用从Javascript获得的FB令牌来设置FB令牌?

$facebook->setAccessToken($new_access_token); $ facebook-> setAccessToken($ new_access_token);

before calling? 打电话之前?

$facebook->getUser() $ facebook-> getUser()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM