Facebook SDK getAccessToken() problems

独自空忆成欢 提交于 2019-12-05 18:24:38

From Facebook SDK:

  public function getAccessToken() {
    if ($this->accessToken !== null) {
      return $this->accessToken;
    }

    $this->setAccessToken($this->getApplicationAccessToken());
    $user_access_token = $this->getUserAccessToken();
    if ($user_access_token) {
      $this->setAccessToken($user_access_token);
    }

    return $this->accessToken;
  }

  protected function getApplicationAccessToken() {
    return $this->appId.'|'.$this->appSecret;
  }

Your access token will be APP ID|APP SECRET which is the application token, or A RANDOM TOKEN HERE, which is the user access token, when you have a user signed:

$facebook->getUser();

When getUser() return 0 (which is same as false, and user not signed) you need to request a login, and authorization (if have not authorized yet) for your application:

if (!$facebook->getUser())
{
    $login_url = $facebook->getLoginUrl(array(
            'scope' => 'publish_stream' // Permissions goes here
        ) 
    );
?>
    <script type="text/javascript">
        top.location.href = " <?php echo $login_url; ?>";
    </script>
<?php
    exit;
}

see available permissions types here: https://developers.facebook.com/docs/authentication/permissions/

Agust Syaputra

$facebook->getAccessToken(); is returning "12345678|abcdefghijklmnop", basically some kind of variable which is made up of the App ID and Secret ID separated by a |

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