dongquanyu5816 2014-12-15 18:03
浏览 109
已采纳

可以通过Facebook Graph API获取我当前的位置吗?

I am trying to build a portion into my personal website that shows the locations I have tagged in my posts on facebook. My understanding is that I need to do an oAuth Request on the server to get the AccessToken:

UPDATE

I built a php file that gets a file with the token in it and refreshes it. I can call this file with a cron job every hour and have an unlimited token. It looks like this:

    $appID = "APPID";
    $appSecret = "APPSECRET";
    $currentToken = file_get_contents(__DIR__."/token.txt");
    $url = "https://graph.facebook.com/oauth/access_token?client_id=".$appID."&client_secret=".$appSecret."&grant_type=fb_exchange_token&fb_exchange_token=".$currentToken;
    $ci = curl_init();
    curl_setopt($ci, CURLOPT_URL, $url);
    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ci, CURLOPT_TIMEOUT, 10);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ci, CURLOPT_FOLLOWLOCATION, TRUE);

    $newtoken = curl_exec($ci);
    curl_close ($ci);

    $newtoken = str_replace("access_token=","",$newtoken);
    $newtoken = substr($newtoken, 0,strpos($newtoken, "&expires=",0));

    if($newtoken == "")
    {
        echo "error";
    }
    else
    {
        $file = __DIR__."/token.txt";
        file_put_contents($file, $newtoken);
        echo $newtoken;
    }
  • 写回答

1条回答 默认 最新

  • dsfasdfsda234234 2014-12-16 08:13
    关注

    If the Access Token has the form {app_id}|{app_secret}, you're not using a User Access Token, but an App Access Token.

    Seems like you don't implement the proper Login process to gather the User Access Token. Stick to the provided sample code of the FB PHP SDK.

    See

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀