无法使用给定的身份验证密钥对 Google 可视化查询语言进行身份验证

发布于 2024-10-27 14:30:31 字数 2175 浏览 4 评论 0 原文

无法验证 Google Spreadsheet API。 我正在使用从此处盗取的代码< /a>,

$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE",
    "Email"   => "[email protected]",
    "Passwd"  => "MY_EMAIL_PASS",
    "service" => "writely",
    "source"  => "MY_APPLICATION_NAME"
);

// Initialize the curl object
$curl = curl_init($clientlogin_url);

// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Execute
$response = curl_exec($curl);

// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];

echo "The auth string is: " . $auth; //this worked!

所以这有效,现在我有一个密钥 但实际使用它...使用下面的代码给我一个用户未验证的错误:

$headers = array(
    "Authorization: GoogleLogin auth=" . $auth,
    "GData-Version: 3.0",
);

$key = 'MY_KEY';

// Make the request
curl_setopt($curl, CURLOPT_URL, 'https://spreadsheets.google.com/tq?tqx=version:0.6;out:json&key='.$key);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);

$response = curl_exec($curl);
curl_close($curl);


var_dump ($response);

这给了我

string(272) "google.visualization.Query.setResponse({version:'0.6',status:'error',errors:[{reason:'user_not_authenticated',message:'User not signed in',detailed_message:'\u003ca target=\u0022_blank\u0022 href=\u0022http://spreadsheets.google.com/\u0022\u003eSign in\u003c/a\u003e'}]});"

所以显然它无法使用Google 可视化查询语言的身份验证密钥..我在做什么错误的?

太感谢了!

Not being able to authenticate Google Spreadsheet API.
I'm using this code stolen from here,

$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE",
    "Email"   => "[email protected]",
    "Passwd"  => "MY_EMAIL_PASS",
    "service" => "writely",
    "source"  => "MY_APPLICATION_NAME"
);

// Initialize the curl object
$curl = curl_init($clientlogin_url);

// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Execute
$response = curl_exec($curl);

// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];

echo "The auth string is: " . $auth; //this worked!

So this works and now I have a key But actually using it...with the bellow code gives me a user not authenticated error:

$headers = array(
    "Authorization: GoogleLogin auth=" . $auth,
    "GData-Version: 3.0",
);

$key = 'MY_KEY';

// Make the request
curl_setopt($curl, CURLOPT_URL, 'https://spreadsheets.google.com/tq?tqx=version:0.6;out:json&key='.$key);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);

$response = curl_exec($curl);
curl_close($curl);


var_dump ($response);

this gives me

string(272) "google.visualization.Query.setResponse({version:'0.6',status:'error',errors:[{reason:'user_not_authenticated',message:'User not signed in',detailed_message:'\u003ca target=\u0022_blank\u0022 href=\u0022http://spreadsheets.google.com/\u0022\u003eSign in\u003c/a\u003e'}]});"

So apparently it is not able to use the authentication key for the Google Visualization Query Language.. what am I doing wrong?

Thank you so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2024-11-03 14:30:31

我会尝试在使用 google 身份验证字符串的代码中进行以下修改:

添加 urlencode

$headers = array(  
   "Authorization: GoogleLogin auth=" . urlencode($auth),  
   "GData-Version: 3.0",  
);

并跳过验证 SSL 证书:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

我已在此 帖子。在那里您将找到一些有关调试 CURL 请求的提示。

I would try the following modifications in the code that uses google authentication string:

add urlencode

$headers = array(  
   "Authorization: GoogleLogin auth=" . urlencode($auth),  
   "GData-Version: 3.0",  
);

and skip verifying SSL sertificates:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

I've described my experience implementing authentication with CURL in this post. There you'll find some tips on debugging CURL requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文