Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 验证OAuth2服务课程(麻烦)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图按照 developer.android.com的课程,我被困在了
am.getAuthToken(
            myaccount_,AUTH_TOKEN_TYPE,options,this,new OnTokenAcquired(),new Handler(new OnError()));

我不知道为myaccount_投入什么;它是与帐户数组相关联的帐户吗? Account [] accounts = accountManager.getAccountsByType(“com.google”);

类OnTokenAcquired上的令牌部分也会产生一个错误,说它不是var,我是否应该将它设为全局变量,即使它在AccountManager.KEY_AUTHTOKEN中是常量?

This is the other link for the Authentication lesson和我在这个tutorIoUl中的DIALOG_ACCOUNTS,showDialog(DIALOG_ACCOUNTS)和manager.getAuthToken(帐户,null,活动,新的AccountManagerCallBACk< Bundle>()收到错误.我没有进一步了解它因为我目前得到的错误.

我不明白为什么会发生这些错误?我认为只是我没有投入正确的变量.

有什么建议?

这是我复制的代码.

public class AccountManagerActivity extends Activity {

AccountManager accountManager = AccountManager.get(this);

Account[] accounts  = accountManager.getAccountsByType("com.google");

String AUTH_TOKEN_TYPE = "Manage your tasks";
String your_api_key;
String your_client_id;
String your_client_secret;
String token;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceStatE) {
    super.onCreate(savedInstanceStatE);
    setContentView(R.layout.main);

    URL url = new URL("https://www.googleapis.com/tasks/v1/users/@me/lists?key=" + your_api_key);
    URLConnection conn = (httpURLConnection) url.openConnection();

    conn.addrequestProperty("client_id",your_client_id);

    conn.addrequestProperty("client_secret",your_client_secret);

    conn.setrequestProperty("Authorization","OAuth " + token);



    AccountManager am = AccountManager.get(this);
    Bundle options = new Bundle();

    am.invalidateAuthToken(token,AUTH_TOKEN_TYPE);
    am.getAuthToken(
        /*Error here*/ myaccount_,// Account retrieved using getAccountsByType()
        AUTH_TOKEN_TYPE,// Auth scope
        options,// Authenticator-specific options
        this,// Your activity
        new OnTokenAcquired(),// CallBACk called when a token is successfully acquired
        new Handler(new OnError()));    // CallBACk called if an error occurs
}

}

然后是OnTokenAcquired类

public class OnTokenAcquired implements AccountManagerCallBACk<Bundle> {

public void run(AccountManagerFuture<Bundle> result) {
    // TODO Auto-generated method stub
    // Get the result of the operation from the AccountManagerFuture.
    Bundle bundle = result.getResult();

    // The token is a named value in the bundle. The name of the value
    // is stored in the constant AccountManager.KEY_AUTHTOKEN.
  /*Error here*/  Token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
    Intent launch = (Intent) result./*Error here*/get(AccountManager.KEY_INTENT);
    if (launch != null) {
       /*Error here*/ startActivityForResult(launch,0);
        return;
    }


}

}

解决方法

am.invalidateAuthToken(token,AUTH_TOKEN_TYPE);

应该

am.invalidateAuthToken(AUTH_TOKEN_TYPE,token);

大佬总结

以上是大佬教程为你收集整理的android – 验证OAuth2服务课程(麻烦)全部内容,希望文章能够帮你解决android – 验证OAuth2服务课程(麻烦)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。