2015-07-13 89 views
1

我在Xamarin Android中執行twitter登錄時遇到問題。 我已經包含了Xamarin.Auth組件,它對Facebook很好。 Fot twitter auth.Completed event is not called ... 我在twitter dev門戶上創建了示例應用程序。Xamarin Android Xamarin.Auth - Twitter

下面是從應用我的代碼:

private void LoginTwitter() 
    { 
     var auth = new OAuth1Authenticator(
        consumerKey: "3v7rOXkdexGYhQmr3HVhtGgPO", 
        consumerSecret: "mGhRjee87tAp4X0vHUmMIohWoYy0JGg9zFGyin7CigFP64y3j5", 
        requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"), 
        authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"), 
        accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"), 
        callbackUrl: new Uri("http://twitter.com") 
      ); 
     auth.AllowCancel = true; 
     StartActivity(auth.GetUI(this)); 
     auth.Completed += (s, eventArgs) => 
     { 
      if (eventArgs.IsAuthenticated) 
      { 

       Account loggedInAccount = eventArgs.Account; 
       //save the account data for a later session, according to Twitter docs, this doesn't expire 
       AccountStore.Create(this).Save(loggedInAccount, "Twitter"); 
      } 
     }; 
    } 

我希望有人可以幫助。

回答

6

好吧,我已經自己解決了這個問題。 當創建新OAuth1Authenticator 回調URL應設置爲mobile.twitter.com不twitter.com

callbackUrl: new Uri("http://mobile.twitter.com") 

之後,你將能夠獲得令牌。

希望它能幫助未來的人。 :)

編輯:您需要使用http://mobile.twitter.com/home NOW-

+0

非常感謝!! :) –

+1

只是一個快速更新到這一點,他們現在重定向到這個地址:https://mobile.twitter.com/home,所以你現在需要使用這個作爲回調。 – Richard

0

我認爲你需要移動你的Completed事件處理,因爲我相信StartActivity被阻止。

private void LoginTwitter() 
{ 
    var auth = new OAuth1Authenticator(
       consumerKey: "3v7rOXkdexGYhQmr3HVhtGgPO", 
       consumerSecret: "mGhRjee87tAp4X0vHUmMIohWoYy0JGg9zFGyin7CigFP64y3j5", 
       requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"), 
       authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"), 
       accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"), 
       callbackUrl: new Uri("http://twitter.com") 
     ); 
    auth.AllowCancel = true; 
    auth.Completed += (s, eventArgs) => 
    { 
     if (eventArgs.IsAuthenticated) 
     { 

      Account loggedInAccount = eventArgs.Account; 
      //save the account data for a later session, according to Twitter docs, this doesn't expire 
      AccountStore.Create(this).Save(loggedInAccount, "Twitter"); 
     } 
    }; 

    StartActivity(auth.GetUI(this)); 
} 
+0

謝謝你,但它仍然沒有工作...:( –