Facebook API登录错误 - 会话已过期验证访问令牌

时间:2016-04-29 21:50:32

标签: php facebook facebook-php-sdk

我正在登录Facebook登录错误,有时我会看到:

Sub copydata()

Dim path As String
path = InputBox("Please input path")

Application.ScreenUpdating = False

Dim actualfile As Workbook
Set actualfile = ActiveWorkbook

Dim script As Object
Set script = CreateObject("Scripting.FileSystemObject")

Dim catalogue As Object
Set catalogue = script.GetFolder(path)

Application.DisplayAlerts = False
Application.AskToUpdateLinks = False

Dim textfile As Object
For Each textfile In catalogue.Files

    Workbooks.Open textfile

    Dim loadedfile As Workbook
    Set loadedfile = ActiveWorkbook

    loadedfile.Worksheets(1).Range("A2").CurrentRegion.Offset(1, 0).Copy

    actualfile.Worksheets(1).Range("A2").Offset(1, 0).End(xlUp).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    loadedfile.Close Savechanges:=False

Next textfile

Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True

可能导致这种情况的原因是什么?我假设有人进入网站,代码生成,然后他在38分钟后点击登录,令牌已过期。我该如何防止这种情况?

我的代码是这样的:

OAuthException: Error validating access token: 
Session has expired on Friday, 29-Apr-16 14:00:00 PDT. 
The current time is Friday, 29-Apr-16 14:38:54 PDT.

1 个答案:

答案 0 :(得分:0)

    Please Used this code. This code is working in my web.
    $fbconfig['appid' ] =   "your_app_id";
    $fbconfig['secret']    =    "your_secret_key";
    $fbconfig['baseurl']   =    "your_redirect_url"; 

    $user                   =   null; //facebook user uid      
    // Create our Application instance.
    $facebook = new Facebook(array('appId'  => $fbconfig['appid'],'secret' => $fbconfig['secret'],'cookie' => true,));
    //Facebook Authentication part
    $user       = $facebook->getUser();
    // We may or may not have this data based   
    $loginUrl   = $facebook->getLoginUrl (
        array (
            'scope'         => 'email,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
            'redirect_uri'  => $fbconfig['baseurl']
        )
    );
    $logoutUrl  = $facebook->getLogoutUrl();
    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile =  $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
          echo "<pre>";print_r($user_profile);die;
       }  catch (FacebookApiException $e) {
        //you should use error_log($e); instead of printing the info on browser
        d($e);  // d is a debug function defined at the end of this file
        $user = null;
      }
  }
相关问题