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

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

报告相同问题?