首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级Facebook版本

升级Facebook版本
EN

Stack Overflow用户
提问于 2016-06-22 08:07:59
回答 1查看 1.7K关注 0票数 2

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

GraphAPIv2.1升级注意事项 foobarapplication最近对Graph v2.0进行了API调用,它将在2016年8月8日(星期一)结束两年期的反对意见窗口。请将所有调用迁移到v2.1或更高版本,以避免潜在的中断体验。 我们建议使用新的Graph升级工具来查看哪些调用受到此更改的影响,以及更新版本中的任何替换调用。您还可以使用我们的changelog查看更改的完整列表。

一年前,我通过提取PHP和更改源代码用法,为给定的PHP应用程序升级了Facebook。登录审查是成功的,没有严重的问题,从那时起。然而,该应用程序需要尽快从FacebookAPI2.0中升级。我对如何做到这一点有一个想法,但不确定我是否正确。让我们考虑以下功能:

FacebookRedirectLoginHelper类:

代码语言:javascript
复制
  /**
   * 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类:

代码语言:javascript
复制
  /**
   * 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类:

代码语言:javascript
复制
  /**
   * 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。我的方法可行吗,还是应该使用一个新的客户端库?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-28 13:17:58

事实证明,我的版本是最新的,我不需要为Facebook升级到2.1版做任何修改。除了更改使用的版本号之外。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37962140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档