我正在尝试关注developer.android.com的课程而我正陷入困境
am.getAuthToken(
myAccount_, AUTH_TOKEN_TYPE,options,this,new OnTokenAcquired(),new Handler(new OnError()));
我无法获得myAccount_的内容;它是与帐户数组相关联的帐户吗? Account[] accounts = accountManager.getAccountsByType("com.google");
class OnTokenAcquired
上的令牌部分也会产生一个错误,表示它不是变量,我应该将其设为全局变量,即使它是AccountManager.KEY_AUTHTOKEN
中的常量也是如此?
This is the other link for the Authentication lesson我在该tutorioul中收到了DIALOG_ACCOUNTS
,showDialog(DIALOG_ACCOUNTS)
和manager.getAuthToken(account, AUTH_TOKEN_TYPE, null, activity, new 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;
}
}
}
答案 0 :(得分:1)
am.invalidateAuthToken(token, AUTH_TOKEN_TYPE);
应该是
am.invalidateAuthToken(AUTH_TOKEN_TYPE, token);