Is it possible to call the email settings API using 2 leg OAuth?

151 views
Skip to first unread message

Dan Esparza

unread,
Jul 10, 2011, 11:32:03 PM7/10/11
to google-app...@googlegroups.com
Is it possible to call the email settings API using 2 leg OAuth?

Alexandre Jacquet

unread,
Jul 11, 2011, 12:05:03 AM7/11/11
to google-app...@googlegroups.com

Yes, it is. But i think 3legged is better

On Jul 11, 2011 12:32 AM, "Dan Esparza" <espar...@gmail.com> wrote:
> Is it possible to call the email settings API<http://code.google.com/googleapps/domain/email_settings/developers_guide_protocol.html> using
> 2 leg OAuth?
>
> --
> You received this message because you are subscribed to the Google Groups "Google Apps Domain Information and Management APIs" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/google-apps-mgmt-apis/-/FfjT3SMA6lMJ.
> To post to this group, send email to google-app...@googlegroups.com.
> To unsubscribe from this group, send email to google-apps-mgmt...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-apps-mgmt-apis?hl=en.
>

Dan Esparza

unread,
Jul 12, 2011, 3:28:15 AM7/12/11
to google-app...@googlegroups.com
Can I please have a working code sample?  

Here is my current manifest:
<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
    <Name>Cagedtornado awesome test app</Name>
    <Description>Demonstrates a simple but awesome Cagedtornado Google Apps Marketplace application</Description>
 
    <!-- Administrators and users will be sent to this URL for application support -->
    <Support>
        <Link rel="support" href="http://www.cagedtornado.com" />
    </Support>
 
    <!-- Show this link in Google's universal navigation for all users -->
    <Extension id="navLink" type="link">
        <Name>Hello World</Name>
        <Url>http://testapp.cagedtornado.com/account/login?from=google&amp;domain=${DOMAIN_NAME}</Url>
        <Scope ref="calendarAPI"/>
        <Scope ref="emailSettingsAPI"/>
    </Extension>
 
    <!-- Declare our OpenID realm so our app is white listed -->
    <Extension id="realm" type="openIdRealm">
        <Url>http://testapp.cagedtornado.com/</Url>
    </Extension>
 
    <!-- Need access to the Calendar API -->
    <Scope id="calendarAPI">
        <Url>https://www.google.com/calendar/feeds/</Url>
        <Reason>This app displays the user's next upcoming Google Calendar appointment.</Reason>
    </Scope>
    <Scope id="emailSettingsAPI">
        <Url>https://apps-apis.google.com/a/feeds/emailsettings</Url>
        <Reason>This app adjusts vacation autoresponders.</Reason>
    </Scope>
</ApplicationManifest>

I'm currently using this code to get calendar information, and it works great:

//  Create an OAuth factory to use
GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("c1", APPLICATION_NAME);
 
//  Available from vendor profile page (next to each application)
//  when logged into the Marketplace
requestFactory.ConsumerKey = "consumer_key_removed";
requestFactory.ConsumerSecret = "consumer_secret_removed";
 
//  Create the CalendarService and set its RequestFactory
CalendarService service = new CalendarService(APPLICATION_NAME);
service.RequestFactory = requestFactory;
 
//  Query the service with the parameters passed to the function
//  NOTE: THIS GETS EVENTS IN THE FUTURE - if you don't have events in the future in
//  the target calendar, they won't show up here.
EventQuery query = new EventQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/private/" + projection);
query.OAuthRequestorId = requestorId;
query.NumberToRetrieve = maxResults;
query.SingleEvents = singleEvents;
query.StartTime = DateTime.Now;
query.SortOrder = CalendarSortOrder.ascending;
 
EventFeed resultFeed = service.Query(query);
return resultFeed;

But when I try to use this code to get email settings, it fails with a 401 error on the line that calls 'RetrieveVacation'.
//  Create an OAuth factory to use
GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("m1", APPLICATION_NAME);
 
//  Available from vendor profile page (next to each application)
//  when logged into the Marketplace
requestFactory.ConsumerKey = "consumer_key_removed";
requestFactory.ConsumerSecret = "consumer_secret_removed";
requestFactory.UseSSL = true;
 
GoogleMailSettingsService service = new GoogleMailSettingsService(domain, APPLICATION_NAME);
service.RequestFactory = requestFactory;
 
AppsExtendedEntry vacation = service.RetrieveVacation(requestorId);
return vacation.Title.Text;

I'm pulling my hair out.  Please help!

Jay Lee

unread,
Jul 12, 2011, 10:24:59 AM7/12/11
to google-app...@googlegroups.com
I do not believe 2LO is possible with Email Settings API. The primary domain key/secret at:


only gives you access to the user data APIs (Calendar, Contacts, Docs List, etc), not the Admin APIs like Provisioning and Email Settings.

Marketplace Vendors and anyone you manually give access can do limited read-only provisioning API calls via 2LO but have no access to Email Settings API.

As far as I know, Email Settings API is only accessible via 3LO of a domain admin right now (and ClientLogin of course). That's how my program, Google Apps Manager (GAM) does it.

Jay

Alexandre Jacquet

unread,
Jul 12, 2011, 11:18:46 AM7/12/11
to google-app...@googlegroups.com
Uhmm I thougth the only limitation of 2LO was Provisioning API... 



                                                                                           

Alexandre Jacquet

Google Apps Deployment Specialst 
São Paulo | SP | Brasil
Tel.: 55 11 8064 6882






--
You received this message because you are subscribed to the Google Groups "Google Apps Domain Information and Management APIs" group.

Dan Esparza

unread,
Jul 12, 2011, 11:49:27 AM7/12/11
to google-app...@googlegroups.com
Thanks, Jay.  

With 3LO, do you know if there are any limitations on the types of accounts I can access with the Email Settings API?  For example, only Educational or Premier accounts? 

I can get the authorization prompt (and then the access token and token secret) but then I get a 403 'Domain cannot use API' when I try to use the credentials with the email settings API.  Any ideas why I would get this?

Thanks,
-D

Jay Lee

unread,
Jul 12, 2011, 11:57:24 AM7/12/11
to google-app...@googlegroups.com
The Email Settings API, like all of the Admin APIs, will not work with Standard/Free Google Apps Domains. The only thing Free domains can use is limited read-only provisoning API calls with Marketplace apps (so that Marketplace apps can pull a list of users, etc).

If you need access to the Admin APIs, you'll need to upgrade to Business (or qualify for EDU).

Jay

khangulll

unread,
Aug 15, 2011, 6:34:31 AM8/15/11
to google-app...@googlegroups.com
Dear Jay Lee I am utterly distressed how am I to use the admin settings api. I've tried the gdata technique and google java api client but how to use them is the problem. Follwing is a piece of code and its resulklt, I've removed my username and password, the rest is the code I'm running

Hello,
          I have a problem where I am getting a service forbidden exception 403 after running this piece of code. I want to change the language of my account, and ideally I would like to do it through an acquired token. I am getting the token and everything but to change the language it is not changing it.
Following is the basic code. could you please help since this is a critical task vital to our application

 public String changeLanguage()
    {
        try
        {
//            FacesContext.getCurrentInstance().getExternalContext().redirect("https://accounts.google.com/o/oauth2/auth?client_id=9999999.apps.googleusercontent.com&redirect_uri=http://localhost:8080/testproj/faces/googleConnect.xhtml&scope=https://apps-apis.google.com/a/feeds/emailsettings/2.0/&response_type=token");
            System.out.println("1");
            GmailSettingsService service = new GmailSettingsService("HamConnect", "gmail.com", "username", "password");
            System.out.println("2");
            List<String> list = new ArrayList<String>();
            System.out.println("3");
            String users = "user...@gmail.com";
            System.out.println("4");
            list.add(users);
            System.out.println("5");
            service.changeLanguage(list, "de");
            System.out.println("6");
        }
        catch(ServiceForbiddenException ex)
        {
            System.out.println("Why am I here?????????????");
            ex.printStackTrace();
        }
        catch(AuthenticationException ex)
        {
            ex.printStackTrace();
            Logger.getLogger(GoogleConnectMB.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch(ServiceException ex)
        {
            ex.printStackTrace();
            Logger.getLogger(GoogleConnectMB.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IOException ex)
        {
            Logger.getLogger(GoogleConnectMB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return "";
    }

This is the out put for this code..

INFO: 1
INFO: 2
INFO: 3
INFO: 4
INFO: 5
INFO: Updating language settings ( language: ar ) for user user...@gmail.com ...
INFO: Why am I here?????????????
SEVERE: com.google.gdata.util.ServiceForbiddenException: Invalid domain.
<HTML>
<HEAD>
<TITLE>Invalid domain.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Invalid domain.</H1>
<H2>Error 403</H2>
</BODY>
</HTML>



REgards
Khangulll


PS: Please Help this is a very critical task.

Jay Lee

unread,
Aug 15, 2011, 11:51:40 AM8/15/11
to google-app...@googlegroups.com
Hi Khangulll,

  Are your users actually using @gmail.com email accounts? There is no way to use the Google Apps Admin APIs with @gmail.com accounts since Gmail is a personal service.

  You'll need to purchase a Google Apps for Business domain and create/maintain your users there.


Jay

khangulll

unread,
Aug 15, 2011, 1:43:37 PM8/15/11
to google-app...@googlegroups.com
Dear Jay,
        Thanks for replying. My main objective is to get some settings to change through code for gmail users, so that they can use our interface to change the language and then it would replicate the next time they login to gmail. Settings like timezone, Language etc. so that it looks in sync with our core app.  Is it possible. If not through google apps. Any other way would be alright as well if we could do it through code, they way we can check messages and contacts through code as well, that works fine, but I cant seem to change any settings for the account for the authenticated user who has logged in. Tried it through 3 legged OAuth as well. Is there a right way of doing this, or is this possible. thank you

khangulll

unread,
Aug 17, 2011, 2:59:50 AM8/17/11
to google-app...@googlegroups.com
Hey Jay,
       I tried gooleapps for business, and am using my own domain now, it is working. But still to change the language it takes about 20 minutes toi come into effect where you can see the actual change. Furthermore I wanted to ask,
how to get user credentials e.g (username or password) through token access. and how to use the above mentioned service through token without having to hard code the username and password again. A prompt reply would be greatly appreciated, since were in the middle of deployment. Thank you

khangulll

Jay Lee

unread,
Aug 17, 2011, 7:57:25 AM8/17/11
to google-app...@googlegroups.com
Hi khangulll,

Responses inline.


On Wednesday, August 17, 2011 2:59:50 AM UTC-4, khangulll wrote:
       I tried gooleapps for business, and am using my own domain now, it is working. But still to change the language it takes about 20 minutes toi come into effect where you can see the actual change.

This is the normal, expected behavior. language changes can take 15 minutes to an hour to take effect in the user's UI. The user may need to log out and back in to see them also.
 
how to get user credentials e.g (username or password) through token access. and how to use the above mentioned service through token without having to hard code the username and password again. A prompt reply would be greatly appreciated, since were in the middle of deployment. Thank you

I don't understand what you're asking here. For security reasons, it's not possible to retrieve a user's current password via any API if that's your question. You can only reset it to something else. If you don't want to use a username/password to work with the APIs, you want to use OAuth. See below for documentation on OAuth. If you're looking for sample code, my application, Google Apps Manager (GAM) makes use of the Email Settings API and OAuth among other APIs:



Jay

khangulll

unread,
Aug 18, 2011, 2:02:22 AM8/18/11
to google-app...@googlegroups.com
Hey thanks,
               But could I see some sample in java where OAuth is used and using the n email settings API.
Thank you

khangulll

unread,
Aug 23, 2011, 1:15:02 AM8/23/11
to google-app...@googlegroups.com
Hey, thanks for all the help,
   I have one question remaining, why does the API sometimes doesn't respond or authorise, is there a limit on number of queries per day for this particular API, or is it because the API locks because sometimes I gave null parameters to some commands.

Regards
khangulll

PS: Urgent reply needed demo in couple of hours
Reply all
Reply to author
Forward
0 new messages