谷歌Android阿比对于s preadSheet [英] Android Google Api for SpreadSheet
问题描述
我想弄清楚如何使用谷歌API,用于访问/修改谷歌小号preadSheet。
我想有许多设备相同的S preadsheet总是连接。我使用的AccountManager的例子,但我不应该使用的用户帐户。有什么好的turorial?
现在我已经得到了following..is这样吗?
的AccountManager的AccountManager = AccountManager.get(本);
ArrayList的googleAccounts =新的ArrayList();
//只是为了举例来说,我现在用的是谷歌第一次返回账户。
帐户帐户=新帐户(email@gmail.com,com.google); //聪明=谷歌小号preadheets
AccountManagerFuture<群组> AMF = accountManager.getAuthToken(帐户,聪明,空,为此,NULL,NULL); 尝试{
捆绑authTokenBundle = amf.getResult();
字符串的authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN); //做一些与令牌
// InputStream的响应= sgc.getFeedAsStream(feedUrl,的authToken,NULL,2.1); }
赶上(例外五){
// TODO:处理异常
}
必需的权限:
<使用许可权的android:NAME =android.permission.ACCOUNT_MANAGER/>
<使用许可权的android:NAME =android.permission.GET_ACCOUNTS/>
<使用许可权的android:NAME =android.permission.USE_CREDENTIALS/>
选择从表所需OUTH令牌类型:
的http://$c$c.google.com/intl/ja/apis/s$p$padsheets/faq_gdata.html#Authentication
取值preadsheets数据API 明智
code样品:</ STRONG>
公共类OuthTokenActivity延伸活动{
字符串标记=DEBUG@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main); 的AccountManager mAccountManager = AccountManager.get(本);
对于(账户账号:mAccountManager.getAccountsByType(com.google)){
mAccountManager.getAuthToken(帐户,聪明,savedInstanceState,
对此,resultCallback,NULL);
}
}AccountManagerCallback&LT;群组&GT; resultCallback =新AccountManagerCallback&LT;&捆绑GT;(){
公共无效的run(AccountManagerFuture&LT;群组&GT;未来){
尝试{
捆绑的结果= future.getResult();
字符串标记=(字符串)result.get(AccountManager.KEY_AUTHTOKEN);
字符串名称=(字符串)result.get(AccountManager.KEY_ACCOUNT_NAME);
Log.d(标签的String.format(名称:%s,令牌:%S,名称,标记));
}赶上(例外五){
e.printStackTrace();
}
}
};
}
I'm trying to figure out how to use Google Api for accessing/editing Google SpreadSheet. I want to have a connection always with the same spreadsheet from many devices. I got examples using the AccountManager, but i should not use the user account. There is any good turorial? Right now i've got the following..is that right?
AccountManager accountManager = AccountManager.get(this); ArrayList googleAccounts = new ArrayList();
// Just for the example, I am using the first google account returned.
Account account = new Account("email@gmail.com", "com.google");
// "wise" = Google Spreadheets
AccountManagerFuture<Bundle> amf = accountManager.getAuthToken(account, "wise", null, this, null, null);
try {
Bundle authTokenBundle = amf.getResult();
String authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
// do something with the token
//InputStream response = sgc.getFeedAsStream(feedUrl, authToken, null, "2.1");
}
catch (Exception e) {
// TODO: handle exception
}
Required permissions:
<uses-permission android:name="android.permission.ACCOUNT_MANAGER"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
Choose needed outh token type from the table:
http://code.google.com/intl/ja/apis/spreadsheets/faq_gdata.html#Authentication
Spreadsheets Data API wise
Code sample:
public class OuthTokenActivity extends Activity {
String tag = "DEBUG";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AccountManager mAccountManager = AccountManager.get(this);
for (Account account : mAccountManager.getAccountsByType("com.google")) {
mAccountManager.getAuthToken(account, "wise", savedInstanceState,
this, resultCallback, null);
}
}
AccountManagerCallback<Bundle> resultCallback = new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle result = future.getResult();
String token = (String) result.get(AccountManager.KEY_AUTHTOKEN);
String name = (String) result.get(AccountManager.KEY_ACCOUNT_NAME);
Log.d(tag, String.format("name: %s, token: %s", name, token));
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
这篇关于谷歌Android阿比对于s preadSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!