2011-03-29 5 views
0

Google 스프레드 시트 API를 인증 할 수 없습니다. 내가 here에서 도난이 코드를 사용하고 ,주어진 인증 키로 Google 시각화 쿼리 언어를 인증 할 수 없습니다.

$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 Visualization Query Language .. 내가 뭘 잘못하고 있니?

정말 고마워요!

답변

1

내가 구글 인증 문자열을 사용하는 코드에서 다음과 같은 수정을 시도 할 것 :

urlencode

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

를 추가 및 SSL sertificates 확인 건너 뛰기 : 내가 설명한

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

을 내 이 post에서 CURL을 통한 인증 구현 경험. 여기에서 CURL 요청 디버깅에 대한 몇 가지 팁을 찾을 수 있습니다.

+0

천재적입니다. – Mohammad