Re: Can't curl and get access token key without user intervention in php

130 views
Skip to first unread message

Sérgio Gomes (AdSense API Team)

unread,
May 7, 2013, 7:04:25 AM5/7/13
to adsen...@googlegroups.com
Hi Alex,

Have you considered using the PHP client library for Google APIs? It supports the AdSense APIs, and it will make your life a lot easier where it comes to handling auth!

Here are some links to the library and to our PHP code samples.

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902

On Friday, 3 May 2013 19:17:44 UTC+1, Alex Inigo wrote:
I'm currently trying to get an access token by passing the following parameters into the https://accounts.google.com/o/oauth2/auth URL, but I keep getting a page that says "Moved Temporarily / The document has moved here," with here linked to another page. Is there any way to access just the URL I mentioned above without having to load this new page? When I click the "here" it's able to give me an access token after that. I just started working with Google APIs, so any assistance is appreciated.

Here's my code:

<?php
 
        $ch = curl_init();
$qs_vars = array(
"access_type" => "offline",
"approval_prompt" => "auto",
"response_type" => "code",
);
foreach ($qs_vars as $key => $value) {
if (empty($query_string)) {
$query_string .= "?";
} else {
$query_string .= "&";
}
$query_string .= $key."=".$value;
}
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/auth".$query_string);
$response = curl_exec($ch);
curl_close($ch);

?>
Reply all
Reply to author
Forward
0 new messages