【问题标题】:Facebook PHP SDK for Graph API用于图形 API 的 Facebook PHP SDK
【发布时间】:2011-08-08 12:52:29
【问题描述】:

是否可以在我的日志文件中打印从 Facebook PHP SDK 到 Facebook Graphs Server 的确切请求?

谁能解释我如何修改 Facebook PHP 库https://github.com/facebook/php-sdk

我找到了:

/**
* Invoke the Graph API.
*
* @param String $path the path (required)
* @param String $method the http method (default 'GET')
* @param Array $params the query/post data
* @return the decoded response object
* @throws FacebookApiException
*/
protected function _graph($path, $method = 'GET', $params = array()) {
if (is_array($method) && empty($params)) {
  $params = $method;
  $method = 'GET';
}
$params['method'] = $method; // method override as we always do a POST

$result = json_decode($this->_oauthRequest(
  $this->getUrl('graph', $path),
  $params
), true);

// results are returned, errors are thrown
if (is_array($result) && isset($result['error'])) {
  $this->throwAPIException($result);
}

return $result;
}

【问题讨论】:

    标签: php html facebook-graph-api facebook-php-sdk


    【解决方案1】:

    您应该看一下发生实际 http 请求的 makeRequest 函数。由于我不会在 api 中玩耍,您还可以扩展类并覆盖方法:

    class FacebookLogger extends Facebook {
    
        protected function makeRequest($url, $params, $ch=null) {
    
            var_dump($url);
            var_dump($params);
    
            parent::makeRequest($url, $params, $ch);
    
        }
    
    }
    

    【讨论】:

    • 非常感谢伙计。我应该把这个放在哪里?在 facebook.php 或 base_facebook.php 中,或者在我的代码中?
    • 创建一个新文件(例如 fb_logger.php),包括它(和官方 fb api),而不是 new Facebook 写 new FacebookLogger。
    • 非常感谢。真的很有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    相关资源
    最近更新 更多