Javascript API GData: New GoogleService

103 views
Skip to first unread message

kumar

unread,
Feb 6, 2009, 11:26:08 AM2/6/09
to Google Data Protocol
I planning to use GData Spreadsheets Service using Javascript API, for
which there is no API's provided.

As anyone tried this and succeeded ?


Example:
myService = new GoogleService('wise','exampleCo-exampleApp-1');

kumar

unread,
Feb 6, 2009, 11:26:55 AM2/6/09
to Google Data Protocol

Eric (Google)

unread,
Feb 6, 2009, 1:22:44 PM2/6/09
to Google Data Protocol
I posted a tip here that may get you started:
http://gdatatips.blogspot.com/2008/12/using-javascript-client-library-w-non.html

Eric

kumar

unread,
Feb 7, 2009, 3:17:05 PM2/7/09
to Google Data Protocol
Thank you for your suggestion very helpful.

However I get a following error when I use Client Login Authentication
model, any suggestions.


Error:Access to restricted URI denied

CODE:

(Following is the full source code... I have changed my developer key
and password in the user credential.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/x-www-
form-urlencoded"/>
<title>My Google Data API Application</title>
<script src="http://www.google.com/jsapi?key=ABQ..."
type="text/javascript"></script>
<script type="text/javascript">
google.load('gdata', '1.x');
google.setOnLoadCallback(initialize);

function initialize() {
//alert ('inside.');
var scope = 'http://docs.google.com/feeds/documents/private/full';
var service = new google.gdata.client.GoogleService('writely',
'DocList-App-v1.0');
service.setUserCredentials("kumaravel...@gmail.com",
"xxx");
service.getFeed(scope, handleFeed, handleError);
//alert('outside');

};

var handleFeed = function(response) {
var entries = response.feed.entry;
if (!entries.length) {
alert('You have no entries!');
return;
}
var html = [];
for (var i = 0, entry; entry = entries[i]; i++) {
var title = entry.title.$t;
html.push('<li>' + title + '</li>');
}
document.getElementById('data').innerHTML = html.join('');
};

var handleError = function(e) {

if (e && e.cause) {
alert ('Error:' + e.cause.statusText);
} else if (e) {
alert('Error:' + e.message);
} else {
alert ('Error:');
}

};
</script>
</head>
<body>

<div id="data"><!-- dynamically filled --></div>
</body>
</html>




On Feb 6, 12:22 pm, "Eric (Google)" <api.e...@google.com> wrote:
> I posted a tip here that may get you started:http://gdatatips.blogspot.com/2008/12/using-javascript-client-library...

Eric (Google)

unread,
Feb 7, 2009, 3:32:23 PM2/7/09
to Google Data Protocol
The JavaScript client supports ClientLogin. In order to enable it,
you should use the
setUserCredentials method on GoogleService:
http://code.google.com/apis/gdata/jsdoc/1.7/google/gdata/client/GoogleService.html#setUserCredentials

However, ClientLogin requires the ability to make cross-domain
xmlhttprequests
(similar to how this is allowed in FF extensions, google desktop,
and most non-browser javascript environments). Choosing the
xmlhttprequest transport
happens behind the scenes, and it depends on how the JavaScript client
detects the
environment its running in. If you're in the browser, it's likely
that AuthSub is your only option.

Eric

On Feb 7, 12:17 pm, kumar <kumaravel.kandas...@gmail.com> wrote:
> Thank you for your suggestion very helpful.
>
> However I get a following error when I use Client Login Authentication
> model, any suggestions.
>
> Error:Access to restricted URI denied
>
> CODE:
>
> (Following is the full source code... I have changed my developer key
> and password in the user credential.)
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
>     <head>
>         <meta http-equiv="content-type" content="application/x-www-
> form-urlencoded"/>
>         <title>My Google Data API Application</title>
>         <script src="http://www.google.com/jsapi?key=ABQ..."
> type="text/javascript"></script>
>   <script type="text/javascript">
> google.load('gdata', '1.x');
> google.setOnLoadCallback(initialize);
>
> function initialize() {
>     //alert ('inside.');
>     var scope = 'http://docs.google.com/feeds/documents/private/full';
>     var service = new google.gdata.client.GoogleService('writely',
> 'DocList-App-v1.0');
>     service.setUserCredentials("kumaravel.kandas...@gmail.com",

kumar

unread,
Feb 7, 2009, 4:53:39 PM2/7/09
to Google Data Protocol
Yes, I am using ClientLogin (service.setUserCredentials() method) as
per the API doc.

So what I am understanding is that ClientLogin is Not designed to be
used in an regular 'Browser' client application, because it uses
XMLHttp Request transport behind the scenes and this determination is
done by Javascript Environment. So the only option is to use the
AuthSub authentication.

My primary intentions of using the Javascript API is use in multiple
different smart phone browsers (above code did not run on Android -
404 Error), and remove the server dependency. Said that, Could I use
ClientLogin authentication using the smart phone platform api and
determine the 'Auth' token. And then pass on to the Javascript API for
further gdata feed access ? Like is there a way to set the auth token
using the JS API ?


I appreciate your time. Thank You.











On Feb 7, 2:32 pm, "Eric (Google)" <api.e...@google.com> wrote:
> The JavaScript client supports ClientLogin.  In order to enable it,
> you should use the
> setUserCredentials method on GoogleService:http://code.google.com/apis/gdata/jsdoc/1.7/google/gdata/client/Googl...

Eric (Google)

unread,
Feb 8, 2009, 4:09:43 PM2/8/09
to Google Data Protocol
The best way to do this may be to write an app that uses
OAuth. In that way, you can do asynchronous token exchanges
with the caveat that you'll need to pop open a browser window to the
OAuthAuthorizeToken page. If you don't specify an
oauth_callback url, the user can close the window once they've
authorized the token and exchange the token for an
access token back in your app.

http://code.google.com/apis/accounts/docs/OAuth.html

Eric
Reply all
Reply to author
Forward
0 new messages