升级Facebook API版本

时间:2016-06-22 08:07:59

标签: php facebook api version

我最近收到了Facebook开发者通知:

  

图表API v2.1升级通知

     

foobarapplication一直在对Graph API v2.0进行最近的API调用,   这将在周一的2年弃用窗口结束时,   2016年8月8日。请将所有电话迁移到v2.1或更高版本   避免潜在的破碎经历。

     

我们建议您使用我们的新图谱API升级工具查看您的哪个   呼叫受此更改以及任何替换呼叫的影响   较新的版本。您还可以使用我们的更改日志查看完整列表   变化。

一年前,我通过提取PHP SDK和更改源代码用法,为给定的PHP应用程序升级了Facebook。登录审核成功,此后没有出现严重问题。但是,该应用程序需要尽快从Facebook API 2.0升级。我知道如何实现这一点,但我不确定我是否正确。让我们考虑以下功能:

FacebookRedirectLoginHelper上课:

  /**
   * Stores CSRF state and returns a URL to which the user should be sent to
   *   in order to continue the login process with Facebook.  The
   *   provided redirectUrl should invoke the handleRedirect method.
   *
   * @param array $scope List of permissions to request during login
   * @param string $version Optional Graph API version if not default (v2.0)
   * @param boolean $displayAsPopup Indicate if the page will be displayed as a popup
   *
   * @return string
   */
  public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false)
  {
    $version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
    $this->state = $this->random(16);
    $this->storeState($this->state);
    $params = array(
      'client_id' => $this->appId,
      'redirect_uri' => $this->redirectUrl,
      'state' => $this->state,
      'sdk' => 'php-sdk-' . FacebookRequest::VERSION,
      'scope' => implode(',', $scope)
    );

    if ($displayAsPopup)
    {
      $params['display'] = 'popup';
    }

    return 'https://www.facebook.com/' . $version . '/dialog/oauth?' .
      http_build_query($params, null, '&');
  }

  /**
   * Returns a URL to which the user should be sent to re-request permissions.
   *
   * @param array $scope List of permissions to re-request
   * @param string $version Optional Graph API version if not default (v2.0)
   *
   * @return string
   */
  public function getReRequestUrl($scope = array(), $version = null)
  {
    $version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
    $this->state = $this->random(16);
    $this->storeState($this->state);
    $params = array(
      'client_id' => $this->appId,
      'redirect_uri' => $this->redirectUrl,
      'state' => $this->state,
      'sdk' => 'php-sdk-' . FacebookRequest::VERSION,
      'auth_type' => 'rerequest',
      'scope' => implode(',', $scope)
    );
    return 'https://www.facebook.com/' . $version . '/dialog/oauth?' .
      http_build_query($params, null, '&');
  }

FacebookRequest上课:

  /**
   * FacebookRequest - Returns a new request using the given session.  optional
   *   parameters hash will be sent with the request.  This object is
   *   immutable.
   *
   * @param FacebookSession $session
   * @param string $method
   * @param string $path
   * @param array|null $parameters
   * @param string|null $version
   * @param string|null $etag
   */
  public function __construct(
    FacebookSession $session, $method, $path, $parameters = null, $version = null, $etag = null
  )
  {
    $this->session = $session;
    $this->method = $method;
    $this->path = $path;
    if ($version) {
      $this->version = $version;
    } else {
      $this->version = static::GRAPH_API_VERSION;
    }
    $this->etag = $etag;

    $params = ($parameters ?: array());
    if ($session
      && !isset($params["access_token"])) {
      $params["access_token"] = $session->getToken();
    }
    if (FacebookSession::useAppSecretProof()
      && !isset($params["appsecret_proof"])) {
      $params["appsecret_proof"] = $this->getAppSecretProof(
        $params["access_token"]
      );
    }
    $this->params = $params;
  }

FacebookCurlHttpClient上课:

  /**
   * Detect versions of Curl which report incorrect header lengths when
   * using Proxies.
   *
   * @return boolean
   */
  private static function needsCurlProxyFix()
  {
    $ver = self::$facebookCurl->version();
    $version = $ver['version_number'];

    return $version < self::CURL_PROXY_QUIRK_VER;
  }

我的想法如下:

    从应用程序中调用
  • getLoginUrl; 2.6的版本。应该从现在开始指定
  • 我没有真正使用getReRequestUrl,因此我不会对其进行更改
  • FacebookRequest将使用$version 2.6
  • 进行实例化
  • needsCurlProxyFix将原样保留

基本上,我将使用2014年发布的PHP库,但在调用时指定$ version。我的方法是可行的,还是应该使用新的客户端库?

1 个答案:

答案 0 :(得分:1)

事实证明,我的版本是最新版本,我不需要对Facebook升级到版本2.1进行任何更改。除了更改使用的版本名称。

相关问题