2016-06-22 170 views
2

我最近收到了Facebook的开发者通知:升级Facebook的API版本

图形API v2.1的升级通知

foobarapplication一直在最近的API调用图形API V2.0, 这将在2016年8月8日星期一 周二结束。请将所有呼叫转移到v2.1或更高版本,以便 避免潜在的破坏体验。

我们建议使用我们新的Graph API升级工具来查看您的哪些 电话受此更改影响,以及 更新版本中的任何替换电话。您也可以使用我们的更新日志查看 更改的完整列表。

一年前,我通过提取PHP SDK和更改源代码的用法,升级了Facebook给定的PHP应用程序。登录审查是成功的,从那时起没有严重的问题。不过,该应用需要尽快从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。我的方法是否可行?还是应该使用新的客户端库?

+0

我面临同样的问题你有没有得到任何我们可以升级facebook图形API 2.1到2.6 PHP的饮料谢谢 – usama

+0

@usama,这对我来说是一个非问题,因为我的应用程序已经兼容,所有测试成功了。查看Facebook API升级工具:https://developers.facebook。COM /工具/ api_versioning/241490879195373 在那里你会看到需要改变什么 –

+0

我曾尝试它让我看到这个消息 您的应用已不是图形API的调用足以显示任何信息,或者有没有变化,您在v2.3和v2.7之间选择的方法。 你能告诉我什么,我做错了什么? – usama

回答

1

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