Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to instantiate a com.google.api.services.calendar.Calendar object given an oAuth token?
    primarykey
    data
    text
    <p>I have gotten oAuth Tokens for each calendar that is being used in my android app using this code </p> <pre><code>private HashMap&lt;String, String&gt; getAuthrizedCalendarsOnPhone() { HashMap&lt;String, String&gt; authorized_calendars = new HashMap&lt;String, String&gt;(); AccountManager acctmgr = AccountManager.get(app_context); Account[] accounts = acctmgr.getAccountsByType("com.google"); for (Account account : accounts) { String auth_token_type = "oauth2:https://www.googleapis.com/auth/calendar"; AccountManagerFuture&lt;Bundle&gt; amf = acctmgr.getAuthToken(account, auth_token_type, null, this, null, null); String authToken; try { Bundle authTokenBundle = amf.getResult(); authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN); } catch(Exception e) { authToken = ""; } authorized_calendars.put(account.name, authToken); } return authorized_calendars; } </code></pre> <p>Now how do I instantiate a <code>com.google.api.services.calendar.Calendar</code> object using that oAuth Token so I can access the calendar api on behalf of that user?</p> <p>i.e. so I can do something like this</p> <pre><code>private HashMap&lt;String, HCEvent&gt; getCalendarEvents(String calendar_name) { HashMap&lt;String, HCEvent&gt; return_map = new HashMap&lt;String, HCEvent&gt;(); com.google.api.services.calendar.Calendar service = null; //create a Calendar object using the oauth token for associated with calendar_name com.google.api.services.calendar.model.Events events = service.events().list(calendar_name).setPageToken(pageToken).execute(); /* * do something with the events */ return return_map; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload