Android Google Api for SpreadSheet

痴心易碎 提交于 2019-12-22 17:09:06

问题


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
    }

回答1:


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();
        }
    }
};

}




回答2:


There is an API released now, available for java script, which could be run in your app. And they show how to integrate this into an Android app in a video here.



来源:https://stackoverflow.com/questions/9668459/android-google-api-for-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!