【问题标题】:Xamarin Social component fails to retrieve Twitter json streamXamarin Social 组件无法检索 Twitter json 流
【发布时间】:2013-09-11 23:07:18
【问题描述】:

我正在使用以下内容来阅读 Twitter json。它适用于一个 uri 而不是另一个。 uri 适用于 Twitter API 控制台,但不适用于 Xamarin.Social。我在 Twitter 应用上有读写权限,所以我看不出哪里出错了。

https://api.twitter.com/1.1/account/settings.json   <-- works
https://api.twitter.com/1.1/users/show.json?screen_name=AUserName   <-- fails (see error below)


request.GetResponseAsync ().ContinueWith (response => {

            if (response.IsFaulted)
            {
                Console.WriteLine (response.Exception.Flatten ()); 
            }

            var json = response.Result.GetResponseText ();


System.AggregateException: One or more errors occured ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x0030c] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1606 
   at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00141] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1423 
   --- End of inner exception stack trace ---
   --> (Inner exception 0) System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x0030c] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1606 
   at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00141] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1423 

[快速谷歌搜索给出了这个但不确定它是否相关:https://dev.twitter.com/discussions/15206]

// UPDATE ***********

这需要额外的帮助还是您需要更多详细信息?如果是,那么需要哪些详细信息?

public Account Account
    {
        get
        {
            var task = Service.GetAccountsAsync ()
                .ContinueWith (accounts => 
            {
                return accounts.Result.ToList ().FirstOrDefault ();
            });

            return task.Result;
        }
        set
        {
            AccountStore.Create ().Save (value, SocialPlatform.ToString ());
        }
    }


// later on
// when endpoint = "https://api.twitter.com/1.1/account/settings.json" <-- works, json returned
// when endpoint = "https://api.twitter.com/1.1/users/show.json?screen_name=XXXX" <-- IsFaulted with above error, 

var request = Service.CreateRequest ("GET", endpoint, Account);

        request.GetResponseAsync ().ContinueWith (response => {

            if (response.IsFaulted)
            {
                Console.WriteLine (response.Exception.Flatten ());
                return;
            }

            var json = response.Result.GetResponseText ();
            Console.WriteLine (json);
        });

【问题讨论】:

    标签: json twitter twitter-oauth xamarin social


    【解决方案1】:

    您拨打此电话时似乎未获得授权。

    来自 Xamarin.Social 文档。

    Xamarin.Social 使用 Xamarin.Auth 库来获取和存储 帐户对象。

    每个服务都公开一个 GetAuthenticateUI 方法,该方法返回一个 Xamarin.Auth.Authenticator 对象,可用于对 用户。这样做将自动存储经过身份验证的帐户,以便 以后可以用。

    它在 Twitter API 控制台中工作的原因是你在调用之前已经在那里授权。

    如果您已经在您的应用中进行授权,请发布您用于授权的代码。

    【讨论】:

    • 我添加了更多代码,但调用一个 URL 时成功,但调用另一个 URL 时却没有成功...奇怪吗?
    猜你喜欢
    • 1970-01-01
    • 2015-03-21
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2022-07-28
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多