2011-12-17 34 views
3

我想聽課的developer.android.com,我被陷在 am.getAuthToken( myAccount_, AUTH_TOKEN_TYPE,options,this,new OnTokenAcquired(),new Handler(new OnError()));身份驗證到OAuth2服務課(麻煩)

我不要放什麼在爲myAccount_;它是否與帳戶數組關聯? Account[] accounts = accountManager.getAccountsByType("com.google");

令牌部分上class OnTokenAcquired也gennerating一個錯誤,說這不是一個變種,我應該只是做它,即使它是suposse是在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

嘿@domshyra,這個曾經爲我工作,但只有前幾天就停止工作現在它會拋出這個錯誤com.google.android.gms.auth.GoogleAuthException:Unknown。任何想法爲什麼?我的示波器有問題嗎? https://gist.github.com/lawloretienne/7351151 – toobsco42 2013-11-07 16:51:46

回答

1
am.invalidateAuthToken(token, AUTH_TOKEN_TYPE); 

應該

am.invalidateAuthToken(AUTH_TOKEN_TYPE, token);