1

I'm using the following to read Twitter json. It works with one uri and not another. The uri's work with the Twitter API console but not Xamarin.Social. I have read and write permissions on the Twitter app so I can't see where I'm going wrong.

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 

[quick google search gave this but not sure if its relevant: https://dev.twitter.com/discussions/15206]

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

Does this extra infor help or you need more details? If so then what details are required?

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);
        });
dbc
  • 104,963
  • 20
  • 228
  • 340
fractal
  • 1,649
  • 17
  • 31

1 Answers1

0

It seems like you are not authorised when you make this call.

From Xamarin.Social documentation.

Xamarin.Social uses the Xamarin.Auth library to fetch and store Account objects.

Each service exposes a GetAuthenticateUI method that returns a Xamarin.Auth.Authenticator object that you can use to authenticate the user. Doing so will automatically store the authenticated account so that it can be used later.

The reason why it works in Twitter API console is that you have authorised there prior to making a call.

If you are already authorising in your app then please post the code you use to authorise.

Daria Trainor
  • 5,545
  • 4
  • 23
  • 30