Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP的OAuth Google分析验证_Php_Oauth_Google Analytics Api - Fatal编程技术网

使用PHP的OAuth Google分析验证

使用PHP的OAuth Google分析验证,php,oauth,google-analytics-api,Php,Oauth,Google Analytics Api,我试图让OAuth与Google Analytics合作,但我没有任何运气。我的代码如下所示: require_once('common.inc.php'); $consumerKey = "my.url.net"; $consumerSecret = "nzZ....TX"; $sig_method = "HMAC-SHA1"; $oauth_token = $token ? new OAuthToken($token, $token_secret) : NULL; $token_endpo

我试图让OAuth与Google Analytics合作,但我没有任何运气。我的代码如下所示:

require_once('common.inc.php');

$consumerKey = "my.url.net";
$consumerSecret = "nzZ....TX";
$sig_method = "HMAC-SHA1";
$oauth_token = $token ? new OAuthToken($token, $token_secret) : NULL;
$token_endpoint = '/accounts/OAuthGetRequestToken';
$scope = 'https://www.google.com/analytics/feeds/';
$callback_url = "http://my.url.net/pete/oauth/";
$privKey = NULL;
$params = array('scope' => $scope, 'oauth_callback' => $callback_url);
$url = $token_endpoint . '?scope=' . urlencode($scope);

$consumer = new OAuthConsumer($consumerKey, $consumerSecret);

$req = OAuthRequest::from_consumer_and_token($consumer, $oauth_token, 'GET',
                                             $url, $params);

//$req->sign_request($sig_method, $consumer, $oauth_token, NULL);

echo "<PRE>";
print_r($req);

// Fill response
echo json_encode(array(
    'html_link' => '',
    'base_string' =>  $req->get_signature_base_string(),
    'response' => send_signed_request('GET', $url, array($req->to_header())),
    'authorization_header' => $req->to_header()
));
当我取消注释此行时:

//$req->sign_request($sig_method, $consumer, $oauth_token, NULL);

脚本无法加载,显示服务器错误。我做错了什么?任何建议都会有帮助,谢谢

感谢您的注释标记,这实际上是因为我的“$sig_method”变量实际上只是一个包含“HMAC…”的字符串,而实际上它需要一个名为以下内容的对象:

$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
希望这对将来的人有帮助

大概“服务器错误”是“500内部服务器错误”。请查看服务器的错误日志,了解导致错误的确切原因。你在浏览器中看到的东西对于诊断来说是完全无用的。
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();