-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
75 lines (61 loc) · 2.97 KB
/
README
File metadata and controls
75 lines (61 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Android Library for Google APIs Client Library for Java
Gorl is to provide ways with via Google APIs Client Library for Java
Though it is not sufficient, but avaliable classes are currently:
- client for Google SpreadSheet
- model for Google SpreadSheet
Sample code for Android Application with OAuth1.0a is:
public void onCreate(Bundle savedInstanceState) {
boolean retvalue = false;
String token = getToken(); // get Token from Preferences
String tokenSecret = getTokenSecret(); // get TokenSecret from Preferences
if (token == null || tokenSecret == null) {
GDataSpreadSheetClient client =
new GDataSpreadSheetClient(mAppName, null, null);
OAuthCredentialsResponse response = tryAuthenticate(client, isViewAction, callback_url_str);
if (response != null) {
saveTokenAndTokenSecret(response);
token = response.token;
tokenSecret = response.tokenSecret;
}
}
if (token != null && tokenSecret != null) {
GDataSpreadSheetClient client =
new GDataSpreadSheetClient(mAppName, token, tokenSecret);
client.createEmptySpreadSheets("Your Sheets");
}
}
private OAuthCredentialsResponse tryAuthenticate(GDataSpreadSheetClient client,
boolean isViewAction, String callback_url_str) {
try {
if (!isViewAction && (isTemporary || credentials == null) ) {
isTemporary = true;
client.callback = callback_url_str;
credentials = client.getCredentialsResponse();
GoogleOAuthAuthorizeTemporaryTokenUrl temporaryTokenUrl
= client.getOAuthAuthorizeTemporaryTokenUrl(credentials);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(temporaryTokenUrl.build()));
startActivity(intent);
} else {
if (isViewAction) {
Uri uri = this.getIntent().getData();
if (uri != null) {
Log.d(TAG, "uri: " + uri.toString());
client.callback = null;
OAuthCallbackUrl callbackUrl = new OAuthCallbackUrl(uri.toString());
GoogleOAuthGetAccessToken accessToken = client.getOAuthAccessToken(callbackUrl, credentials);
OAuthCredentialsResponse response = accessToken.execute();
isTemporary = false;
credentials = null;
return response;
}
}
Log.d(TAG, "authenticated()");
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
I am preparing JavaDoc and create any other clients and models for other service.
Please semd me your request, report bugs and so on