dpxnrx11199 2016-01-21 12:11
浏览 284
已采纳

Facebook SDK通过PHP SDK撤销

I'm trying to make a web application with Facebook using PHP SDK I had not any problems installing and running the PHP SDK This is my login script index.php

<?php
session_start();
$app_id = '***************';
$app_secret = '******************************'; 
$my_url = 'https://www.domain.net/';
require_once __DIR__ . '/vendor/autoload.php';
$fb = new Facebook\Facebook(['app_id'=>$app_id,'app_secret'=>$app_secret,'default_graph_version'=>'v2.5',]);
$helper = $fb->getRedirectLoginHelper();
if (isset($_SESSION['facebook_access_token'])){
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
try {
  $fbresponse = $fb->get('/me');
  $fbuserNode = $fbresponse->getGraphUser();
} catch(Exception $e) {
  error_log("index.php: Exception",0);
  $permissions = ['email'/*, 'user_likes'*/];
  $loginUrl = $helper->getLoginUrl('https://www.sofiariders.net/fblog-callback.php', $permissions);
  echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
  exit;
}
?>

It works perfectlyq i'm getting logged in with the facebook but the problem is - the ID of my profile. From the $fbuserNode->getId() i'm getting the id 140261546352183 And Facebook doesn't open my profile by the URL https://www.facebook.com/profile.php?id=140261546352183

For example by using the site findmyfbid.com i'm getting another ID for the same profile - it's 100011050158477 and with that id Facebook successfully opens the URL https://www.facebook.com/profile.php?id=100011050158477

The question is - how can I cat my normal profile ID with the PHP SDK? And why i'm getting wrong id?

  • 写回答

1条回答 默认 最新

  • dourou9477 2016-01-21 12:17
    关注

    That other page is doing something that is not allowed: scraping. It gets your "real" ID directly from your profile page. In an App, you can only get an "App Scoped ID" - which is good enough to identify the user. You can just use the following URL: https://www.facebook.com/140261546352183 - it redirects to your profile.

    In other words: You can´t get the "real" ID anymore, and you don´t need it.

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口