Gadget OAuth2 Authorization

I am developing a gadget ( html, JS

) to run inside ( Google Calendar page

). I need to show the user's tasks there, so I need a connection to Google Task Api

. I need to use authorization OAuth2

and requests like:

GET https://www.googleapis.com/tasks/v1/users/@me/lists 
GET https://www.googleapis.com/tasks/v1/lists/tasklist/tasks

      

Unfortunately I don't have t found description or samples for gadgets with

OAuth2 authorization .

Could you tell me what the section will look like in this case OAuth2

?

 <OAuth2>
   <Service name="[service_name]">
      <Authorization url="https://.../authorize"/>
      <Token url="https://.../oauth2/token"/>
   </Service>
 </OAuth2>

      

Could you approve this code for request? (JS)

 function loadContents(){           
   var url = "https://www.googleapis.com/tasks/v1/users/@me/lists?alt=json";            
   var params = {};
   params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
    params[gadgets.io.RequestParameters.AUTHORIZATION]=gadgets.io.AuthorizationType.OAUTH2;
   params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;     
   params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] ="[service_name]";       
   var callback = function (response) { 
     if (response.oauthApprovalUrl) {
       ...                 
     }                      
   };             
   gadgets.io.makeRequest(url, callback, params);
 }                  

      

+3


source to share


2 answers


The answer is using OAuth instead of OAuth 2.0.

The OAuth section should be:

 <OAuth>
      <Service name="google">
        <Access url="https://www.google.com/accounts/OAuthGetAccessToken" method="GET" /> 
        <Request url="https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/tasks" method="GET" /> 
        <Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback" /> 
      </Service>
    </OAuth>

      



Request [JS]

:

 var params = {};
 url = "https://www.googleapis.com/tasks/v1/users/@me/lists?key=YOUR_API_KEY";
      params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
      params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
      params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "google";
      params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
      params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;

      

To use OAuth1 for the Google Tasks API, we need an API key .

+1


source


The Gadgets API does not support OAuth2. However, the Tasks API supports OAuth1, so you should still be able to get everything to work.



+1


source







All Articles