Twitter Integration In windows Phone 7

天涯浪子 提交于 2020-01-15 05:24:10

问题


I want to get the user information from the twitter and show in windows phone 7. I found some examples for twitter integration.

Link 1

Link 2

But in this examples i can only login to the twitter. I can not post or can not get the user information. Can any one provide a sample application or links for windows phone 7 twitter integration.

After getting login i try like this:

 private void btntest_Click(object sender, RoutedEventArgs e)
    {

        string newURL = string.Format("https://api.twitter.com/1.0/users/show.json?screen_name={0}", userScreenName);

        WebClient webClient = new WebClient();
        webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webBrowser_Navigated);
        webClient.DownloadStringAsync(new Uri(newURL));
    }

    void webBrowser_Navigated(object sender, DownloadStringCompletedEventArgs e)
    {


        if (e.Error != null)
        {
            Console.WriteLine("Error ");
            return;
        }
        Console.WriteLine("Result==> " + e.Result);     
    }

But here i can not get the user information. Please help me to get the user information.

Thanks in advance.

Now i try like this:

public void GetTwitterDetail(string userScreenName)
    {
        var credentials = new OAuthCredentials
          {
              Type = OAuthType.ProtectedResource,
              SignatureMethod = OAuthSignatureMethod.HmacSha1,
              ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
              ConsumerKey = AppSettings.consumerKey,
              ConsumerSecret = AppSettings.consumerKeySecret,
              Token = this.accessToken,
              TokenSecret = this.accessTokenSecret,
              Version = "1.1",
          };

        var restClient = new RestClient
        {
            Authority = "https://api.twitter.com",
            HasElevatedPermissions = true
        };

        var restRequest = new RestRequest
        {
            Credentials = credentials,
            Path = string.Format("/1.1/users/show.json?screen_name={0}",///1.1/users/show.json?screen_name={0}&include_entities=true
                userScreenName),
            Method = WebMethod.Get
        };
        restClient.BeginRequest(restRequest, new RestCallback(test));
    }

    private void test(RestRequest request, RestResponse response, object obj)
    {
        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            Console.WriteLine("Content==> " + response.Content.ToString());
            Console.WriteLine("StatusCode==> " + response.StatusCode);

        });

    }

But I am getting this error:

{"errors":[{"message":"Bad Authentication data","code":215}]}

Please help me how to resolve my problem?


回答1:


Finally i found the Solution..!!! :-)

public void GetTwitterDetail(string _userScreenName)
    {
        var credentials = new OAuthCredentials
          {
              Type = OAuthType.ProtectedResource,
              SignatureMethod = OAuthSignatureMethod.HmacSha1,
              ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
              ConsumerKey = AppSettings.consumerKey,
              ConsumerSecret = AppSettings.consumerKeySecret,
              Token = this.accessToken,
              TokenSecret = this.accessTokenSecret,
          };

        var restClient = new RestClient
        {
            Authority = "https://api.twitter.com/1.1",
            HasElevatedPermissions = true
        };

        var restRequest = new RestRequest
        {
            Credentials = credentials,
            Path = string.Format("/users/show.json?screen_name={0}&include_entities=true", _userScreenName),
            Method = WebMethod.Get
        };

        restClient.BeginRequest(restRequest, new RestCallback(test));

    }

    private void test(RestRequest request, RestResponse response, object obj)
    {
        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            Console.WriteLine("Content==> " + response.Content.ToString());
            Console.WriteLine("StatusCode==> " + response.StatusCode);
        });
    }

Now i got the User's In formations..!!! 5 days struggling comes to end..!! Thanks to all..!!



来源:https://stackoverflow.com/questions/25762349/twitter-integration-in-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!