I've been trying to get Google's AuthSub authentication to work for me, but to no avail. I can get the token (see below) but I cannot use the token in any way.
-To get the token, the user clicks a link where href="https://www.google.com/accounts/AuthSubRequest?next=http%3A%2F%2Fdev.MyTestSite.co m%2F&scope=https%3A%2F%2Fgdata.youtube.com&session =1&secure=0"
That redirects correctly with a token (which has more characters than any of their examples).
- HERE'S THE ISSUE: To turn the single use token into a session token, I've tried this: -
$.ajax({
-
url: "https://www.google.com/accounts/AuthSubSessionToken"
-
,headers: {
-
"Host": "www.google.com"
-
,"Content-Type": "application/x-www-form-urlencoded"
-
,"Authorization": authSub
-
,"User-Agent": "Java/1.5.0_06"
-
,"Accept": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
-
,"Connection": "keep-alive"}
-
,success:
-
function(data) {
-
alert('Data Loaded: ' + data);}
-
,type: 'GET'
-
,dataType: "jsonp"
-
,crossDomain: true
-
});
-
This is returning a 401 Unauthorized error. When I look at the request in firebug, I don't see the correct request headers. Is there something that I'm doing wrong?
I just wanted to share the solution to my problem. I still couldn't get AJAX to work for this GET method, so I used cURL in PHP:
To upgrade the token to a session token: - function sendGetMethod($requestURL, $token) {
-
//Secure example = http://gdatatips.blogspot.com/2008/07/secure-authsub-in-php.html
-
-
$curl = curl_init();
-
curl_setopt($curl, CURLOPT_URL, $requestURL);
-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-
curl_setopt($curl, CURLOPT_FAILONERROR, true);
-
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
-
"Authorization: AuthSub token=\"$token\"")
-
);
-
-
$result = curl_exec($curl);
-
curl_close($curl);
-
-
return $result;
-
}
-
-
function upgradeToken($token) {
-
$response = $this->sendGetMethod("https://www.google.com/accounts/AuthSubSessionToken", $token);
-
-
return $response;
-
}
Also, to post a comment: -
function postComment($comment, $id, $token) {
-
$comment = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:yt='http://gdata.youtube.com/schemas/2007'><content>$comment</content></entry>";
-
$contentLength = strlen($comment);
-
-
$curl = curl_init();
-
curl_setopt($curl, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos/$id/comments");
-
curl_setopt($curl, CURLOPT_POST, true);
-
curl_setopt($curl, CURLOPT_FAILONERROR, true);
-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
-
"Authorization: AuthSub token=\"$token\""
-
,"Content-Type: application/atom+xml"
-
,"Content-Length: $contentLength"
-
,"GData-Version: 2"
-
,"X-GData-Key: key={my_personal_dev_key}" )
-
);
-
-
curl_setopt($curl, CURLOPT_POSTFIELDS, "$comment");
-
-
$result = curl_exec($curl);
-
$info = curl_getinfo($curl);
-
-
if(curl_errno($curl)) {
-
$error_code = curl_errno($curl);
-
$http_code = (string)$info['http_code'];
-
...}
-
-
curl_close($curl);
-
-
return $result;
-
}
1 2731
I just wanted to share the solution to my problem. I still couldn't get AJAX to work for this GET method, so I used cURL in PHP:
To upgrade the token to a session token: - function sendGetMethod($requestURL, $token) {
-
//Secure example = http://gdatatips.blogspot.com/2008/07/secure-authsub-in-php.html
-
-
$curl = curl_init();
-
curl_setopt($curl, CURLOPT_URL, $requestURL);
-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-
curl_setopt($curl, CURLOPT_FAILONERROR, true);
-
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
-
"Authorization: AuthSub token=\"$token\"")
-
);
-
-
$result = curl_exec($curl);
-
curl_close($curl);
-
-
return $result;
-
}
-
-
function upgradeToken($token) {
-
$response = $this->sendGetMethod("https://www.google.com/accounts/AuthSubSessionToken", $token);
-
-
return $response;
-
}
Also, to post a comment: -
function postComment($comment, $id, $token) {
-
$comment = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:yt='http://gdata.youtube.com/schemas/2007'><content>$comment</content></entry>";
-
$contentLength = strlen($comment);
-
-
$curl = curl_init();
-
curl_setopt($curl, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos/$id/comments");
-
curl_setopt($curl, CURLOPT_POST, true);
-
curl_setopt($curl, CURLOPT_FAILONERROR, true);
-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
-
"Authorization: AuthSub token=\"$token\""
-
,"Content-Type: application/atom+xml"
-
,"Content-Length: $contentLength"
-
,"GData-Version: 2"
-
,"X-GData-Key: key={my_personal_dev_key}" )
-
);
-
-
curl_setopt($curl, CURLOPT_POSTFIELDS, "$comment");
-
-
$result = curl_exec($curl);
-
$info = curl_getinfo($curl);
-
-
if(curl_errno($curl)) {
-
$error_code = curl_errno($curl);
-
$http_code = (string)$info['http_code'];
-
...}
-
-
curl_close($curl);
-
-
return $result;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dominic Myers |
last post by:
At the risk of inflaming passions best left alone
I'd like to ask a favour of the members of this
esteemed news-group:
I'm currently engaged on a dissertation which is
investigating AJAX...
|
by: VK |
last post by:
Google Trends is an all new service (started May 10) and I have not
responsability for proper query or data accuracy.
Overall seems pretty close to what could be observed by the post
history in...
|
by: ziobudda |
last post by:
Hi, I want ask you if, for a web portal/application, is better
prototype or Jquery? I don't want to innesc some type of flame, but
after the announce that drupal use JQuery and that the new...
|
by: liketofindoutwhy |
last post by:
I am learning more and more Prototype and Script.aculo.us and got the
Bungee book... and wonder if I should get some books on jQuery (jQuery
in Action, and Learning jQuery) and start learning about...
|
by: Jon Paal [MSMD] |
last post by:
using json like
( {"Records": , "RecordCount":"1" } )
and jquery like:
$.ajax({
....
success: function(json, status) {
|
by: kj |
last post by:
I would like to convert a form that currently uses the traditional
CGI sequence (i.e. the action associated with the form sends a POST
request to a server-side CGI script) to one that uses AJAX to...
|
by: dmjpro |
last post by:
function synchronous_ajax(){
var ajax = null;
if(typeof ActiveXObject!='undefined') ajax = new ActiveXObject("Microsoft.XMLHTTP");
else if(typeof XMLHttpRequest!='undefined') ajax = new...
|
by: Aaron Gray |
last post by:
There does not seem too be anyway to test if two jQuery references are the
same element.
Given :-
... <div id="1"></div ....
Then :-
alert( $("#1") == $("#1"))
|
by: ghjk |
last post by:
I have a php page which is having "sumbit" and "cancel" buttion in default. but when user click submit button I want to hide"submit" button and display "ok" button. How can I do that?
|
by: neovantage |
last post by:
Hi Experts,
I have create a jQuery ui function which delete product from the shopping list. After receiving a jQuery Ajax response i want to bind the same function which load on page load. How can i...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |