Windows phone 7 如何在windows phone7中成功验证后保存google plus的流响应

Windows phone 7 如何在windows phone7中成功验证后保存google plus的流响应,windows-phone-7,Windows Phone 7,我正在将社交网络应用程序google plus集成到我的应用程序中。 经过授权,我得到了成功的回复。 我怀疑我们能否将电子邮件和姓名保存为字符串,并通过导航服务传递到另一个页面 我需要保存流并设置为字符串。如果有人知道,请帮助我 这是我尝试过的代码: using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Wind

我正在将社交网络应用程序google plus集成到我的应用程序中。 经过授权,我得到了成功的回复。 我怀疑我们能否将电子邮件和姓名保存为字符串,并通过导航服务传递到另一个页面

我需要保存流并设置为字符串。如果有人知道,请帮助我

这是我尝试过的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using System.IO.IsolatedStorage;

namespace OwnCloud.View.Page
{
    public partial class GooglePlusLoginPage : PhoneApplicationPage
    {

        public App thisApp = Application.Current as App;
        GooglePlusTokens googlePlusTokens = new GooglePlusTokens();
        GooglePlusUserInfo googlePlusUserInfo = new GooglePlusUserInfo();

        public string result;
        String myemail;
        string Parameters = null;
        string ClientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        string ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxx";
        string RedirctedUri = "http://localhost";

        [DataContract]
        public class GooglePlusAccessToken
        {
            [DataMember(Name = "access_token")]
            public string AccessToken { get; set; }
            [DataMember(Name = "refresh_token")]
            public string RefreshToken { get; set; }
            [DataMember(Name = "expires_in")]
            public string ExpiresIn { get; set; }
            [DataMember(Name = "token_type")]
            public string TokenType { get; set; }

        }
        [DataContract]
        public class GooglePlusUserProfile
        {
            [DataMember(Name = "id")]
            public string id { get; set; }
            [DataMember(Name = "email")]
            public string email { get; set; }
            [DataMember(Name = "name")]
            public string name { get; set; }
            [DataMember(Name = "given_name")]
            public string given_name { get; set; }
            [DataMember(Name = "family_name")]
            public string family_name { get; set; }
            [DataMember(Name = "link")]
            public string link { get; set; }
            [DataMember(Name = "picture")]
            public string picture { get; set; }
            [DataMember(Name = "gender")]
            public string gender { get; set; }
            [DataMember(Name = "birthday")]
            public string birthday { get; set; }

        }
        /*  public class Mylist
          {
              public string Email { get; set; }
              public string Gender { get; set; }
          }*/

        public GooglePlusLoginPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(GooglePlus_LoginPage_Loaded); //load google plus login page 
            var GooglePlusSerializerData = new DataContractJsonSerializer(typeof(GooglePlusAccessToken));

        }

        //load google plus login page 
        void GooglePlus_LoginPage_Loaded(object sender, RoutedEventArgs e)
        {

            var url = "https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=" + RedirctedUri + "&scope=https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile&client_id=" + ClientId;  //http://localhost 
            webBrowserGooglePlusLogin.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));

        }


        private void webBrowserGooglePlusLogin_Navigating(object sender, NavigatingEventArgs e)
        {
            if (e.Uri.Host.Equals("localhost"))
            {
                webBrowserGooglePlusLogin.Visibility = Visibility.Collapsed;

                e.Cancel = true;
                int pos = e.Uri.Query.IndexOf("=");

                //get the access code 
                 string messageCode = pos > -1 ? e.Uri.Query.Substring(pos + 1) : null;

                //when code is not equeals to null get the access token
                if (messageCode != null)
                {
                    //get the access token 
                    Parameters = "code=" + messageCode + "&client_id=" + ClientId + "&client_secret=" + ClientSecret + "&redirect_uri=" + RedirctedUri + "&grant_type=authorization_code";
                    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
                    webRequest.Method = "POST";
                    webRequest.ContentType = "application/x-www-form-urlencoded";

                    //string email="madhu.salvendra@gmail.com";




                    // Start web request
                    webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);



                        NavigationService.Navigate(new Uri("/View/Page/EditAccount.xaml?mailid="+<here i want to pass email-id>, UriKind.Relative));


                }

            }
        }
        void GetRequestStreamCallback(IAsyncResult asynchronousResult)
        {

            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
                // End the stream request operation
                Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);


                byte[] byteArray = Encoding.UTF8.GetBytes(Parameters);

                // Add the post data to the web request
                postStream.Write(byteArray, 0, byteArray.Length);
                postStream.Close();

                // Start the web request
                webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
            }
            catch (WebException ex)
            {
            }

        }
        void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            try
            {
                var request = (HttpWebRequest)asynchronousResult.AsyncState;

                using (var resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
                {
                    using (var streamResponse = resp.GetResponseStream())
                    {
                        var GooglePlusSerializerData = new DataContractJsonSerializer(typeof(GooglePlusAccessToken));
                        var GooglePlusProfileData = GooglePlusSerializerData.ReadObject(streamResponse) as GooglePlusAccessToken;
                        this.Dispatcher.BeginInvoke(
                            (Action<GooglePlusAccessToken>)((GooglePlusUserData) =>
                            {

                                //save the response
                                thisApp.AccessToken = googlePlusTokens.AccessToken = GooglePlusUserData.AccessToken;
                                googlePlusTokens.RefreshToken = GooglePlusUserData.RefreshToken;
                                googlePlusTokens.ExpiresIn = GooglePlusUserData.ExpiresIn;
                                googlePlusTokens.TokenType = GooglePlusUserData.TokenType;


                                // request user profile
                                RequestForUserProfile();


                            }), GooglePlusProfileData);

                    }
                }
            }
            catch (WebException ex)
            {

            }
        }

        //request for user prifile
        void RequestForUserProfile()
        {

            //  var urlProfile = "https://www.googleapis.com/plus/v1/people/me?access_token=" + thisApp.AccessToken;
            var urlProfile = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + thisApp.AccessToken;
            // web request user profile
            WebRequest request = WebRequest.Create(urlProfile);
            request.BeginGetResponse(new AsyncCallback(this.ResponseCallbackProfile), request);

        }


        // user profile response 
        private void ResponseCallbackProfile(IAsyncResult asynchronousResult)
        {

            try
            {
                var request = (HttpWebRequest)asynchronousResult.AsyncState;

                using (var resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
                {
                    using (var streamResponse = resp.GetResponseStream())
                    {
                        var GooglePlusSerializerData = new DataContractJsonSerializer(typeof(GooglePlusUserProfile));
                        var GooglePlusProfileData = GooglePlusSerializerData.ReadObject(streamResponse) as GooglePlusUserProfile;
                        var mydata = GooglePlusSerializerData.ReadObject(streamResponse) as Mylist;
                        this.Dispatcher.BeginInvoke(
                            (Action<GooglePlusUserProfile>)((GooglePlusUserData) =>
                            {

                                thisApp.UserName = googlePlusUserInfo.UserName = GooglePlusUserData.name;
                                thisApp.UserImage = googlePlusUserInfo.UserPicture = GooglePlusUserData.picture;

                                if (thisApp.UserImage == null)
                                {
                                    thisApp.UserImage = googlePlusUserInfo.UserPicture = "https://lh3.googleusercontent.com/-_kvINpT6jtI/AAAAAAAAAAI/AAAAAAAAAAA/IEAclp4PQbk/photo.jpg";
                                }
                                googlePlusUserInfo.UserBidthday = GooglePlusUserData.birthday;


                                thisApp.UserEmail = googlePlusUserInfo.UserEmail = GooglePlusUserData.email;
                                myemail = googlePlusUserInfo.UserEmail;
                                googlePlusUserInfo.UserFamilyName = GooglePlusUserData.family_name;
                                thisApp.UserGender = googlePlusUserInfo.UserGender = GooglePlusUserData.gender;
                                googlePlusUserInfo.UserGivenName = GooglePlusUserData.given_name;
                                googlePlusUserInfo.UserId = GooglePlusUserData.id;
                                googlePlusUserInfo.UserLink = GooglePlusUserData.link;
                                /*  IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                                  if (!settings.Contains("name"))
                                  {
                                      // MessageBox.Show("First Time Add to Isolated Storage");
                                      settings.Add("name", GooglePlusProfileData.email);
                                      settings.Add("id", GooglePlusProfileData.id);
                                      settings.Add("email", GooglePlusProfileData.name);
                                      settings.Add("userType", GooglePlusProfileData.gender);
                                  }
                                  else
                                  {
                                      // MessageBox.Show("Iso Stored Data Updated");
                                      settings["name"] = GooglePlusProfileData.name;
                                      settings["id"] = GooglePlusProfileData.id;
                                      settings["email"] = GooglePlusProfileData.email;
                                      settings["gender"] = GooglePlusProfileData.gender;
                                  }
                                  settings.Save();*/

                            }), GooglePlusProfileData);
                    }
                }
            }
            catch (WebException ex)
            {

            }
        }
    }
}
你应该挪动你的手

NavigationService.Navigate(new Uri("/View/Page/EditAccount.xaml?mailid="+<here i want to pass email-id>, UriKind.Relative));

你的目标是什么?你到底需要做什么?我的目标是获取电子邮件、生日等数据并传递给textbox。在我看来,你的代码应该可以达到这个目的。NavigationService.NavigateNewURI/View/Page/EditAccount.xaml?mailid=+GooglePlusUserData.email,UriKind.Relative;但是它在editaccount页面的文本框中显示空字符串我认为导航应该在这个方法中调用私有void WebBrowser Google PlusLogin_Navigatingobject sender,NavigatingEventArgs e{NavigationService.navigateNewURI/View/Page/EditAccount.xaml?mailid=+googlePlusUserInfo.UserEmail,UriKind.Relative;}如果您遵循此示例。在此之前,您应该导航到另一个带有电子邮件地址的页面。如果您有任何示例,请发布如何获取。请选择符合我要求的。如果您有代码同步windows phone7中的所有图像并一个接一个地上载到服务器,请选择你必须把它邮寄给我。帮帮我
thisApp.UserEmail = googlePlusUserInfo.UserEmail = GooglePlusUserData.email;
myemail = googlePlusUserInfo.UserEmail;
googlePlusUserInfo.UserFamilyName = GooglePlusUserData.family_name;
thisApp.UserGender = googlePlusUserInfo.UserGender = GooglePlusUserData.gender;
googlePlusUserInfo.UserGivenName = GooglePlusUserData.given_name;
googlePlusUserInfo.UserId = GooglePlusUserData.id;
googlePlusUserInfo.UserLink = GooglePlusUserData.link;
NavigationService.Navigate(new Uri("/View/Page/EditAccount.xaml?mailid="+googlePlusUserInfo.UserEmail, UriKind.Relative));