none
Prob with sign-in and photochooser on WP7

    질문

  • (I'm working on a Windows Phone 7 using the LiveSDK - is this the right forum?)

    The code pasted below is from SDK examples.  I'm doing two things (1) a Windows live sign-in and (2) a PhotoChooserTask.  There are some problems...

    The sign-in only works if the phone is connected to my computer.
    The chooser only works if I disconnect the cable from the comoputer.

    So to get it to run as far as it will I deploy to the phone.  run the application again from the phone with the cable connected.  I get signed in.  Then, before I hit the choose button (btnChoosePic) I have to remove the cable.  The chooser runs.  I choose a Pic an then I get "error uploading file: Client_Error.

    What is wrong?


    namespace LiveSDKPlay
    {
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            private LiveConnectClient Client;
            public MainPage()
            {
                InitializeComponent();
            }

            private void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
            {
                if (e.Status == LiveConnectSessionStatus.Connected)
                {
                    Client = new LiveConnectClient(e.Session);
                    infoTextBlock.Text = "Signed in.";
                    Client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(Client_GetCompleted);
                    Client.GetAsync("me", null);
                   
                }
                else
                {
                    infoTextBlock.Text = "Not signed in.";
                    Client = null;
                }
            }

            void Client_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    if (e.Result.ContainsKey("first_name") &&
                        e.Result.ContainsKey("last_name"))
                    {
                        if (e.Result["first_name"] != null &&
                            e.Result["last_name"] != null)
                        {
                            infoTextBlock.Text =
                                "Hello, " +
                                e.Result["first_name"].ToString() + " " +
                                e.Result["last_name"].ToString() + "!";
                            btnChoosePic.IsEnabled = true;
                        }
                    }
                    else
                    {
                        infoTextBlock.Text = "Hello, signed-in user!";
                    }
                }
                else
                {
                    infoTextBlock.Text = "Error calling API: " +
                        e.Error.ToString();
                }

            }

            private void btnChoosePic_Click(object sender, RoutedEventArgs e)
            {
                var picker = new PhotoChooserTask();
                picker.Completed += new EventHandler<PhotoResult>(picker_Completed);
                picker.Show();
            }

            void picker_Completed(object sender, PhotoResult e)
            {
                if (e.Error != null)
                {
                    this.infoTextBlock.Text = "Error choosing photo: " + e.Error.ToString();
                }
                else
                {
                    string[] filePathSegments = e.OriginalFileName.Split('\\');
                    string fileName = filePathSegments[filePathSegments.Length - 1];
                    Client.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(Client_UploadCompleted);   
                    Client.UploadAsync("me/skydrive", fileName, e.ChosenPhoto);
                }

            }

            void Client_UploadCompleted(object sender, LiveOperationCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    IDictionary<string, object> file = (IDictionary<string, object>)e.Result;
                    this.infoTextBlock.Text = "File uploaded. Link: " + file["source"];
                }
                else
                {
                    this.infoTextBlock.Text =
                        "Error uploading file: " + e.Error.ToString();
                }

            }
        }
    }

    xaml:
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <StackPanel>
                    <my:SignInButton Name="btnSignin" ClientId="000000004408D15D" Scopes="wl.signin wl.basic" RedirectUri="http://www.deanblakely.com" Branding="Windows" TextType="SignIn" SessionChanged="btnSignin_SessionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" />
                    <TextBlock Height="32" HorizontalAlignment="Left" Margin="12,5,0,0" Name="infoTextBlock" TextWrapping="Wrap" Text="" Width="419" />
                    <Button x:Name="btnChoosePic" HorizontalAlignment="Left" Content="Choose Pic" Click="btnChoosePic_Click" IsEnabled="False" />
                </StackPanel>
            </Grid>


    .net Developer

    2012년 3월 5일 월요일 오전 12:52

모든 응답

  • from what I can fathom you have a network connectivity issue w/ your phone. It works when connected to the computer because the USB cable acts as a tether; you're using your computer's internet connection.

    Then you must disconnect from PC because you can't open photo hub while syncing. So you do that to pick your photo. Immediately after picking the photo, you attempt an upload, but you don't have network connectivity when you're disconnected from your PC (apparently).

    You can do a couple of things to make this test scenario work for you:

    1) Detect network connectivity BEFORE attempting the upload. Prompt the user.

    2) Add another step after picking the photo that requires user interaction to kick off the upload. Obviously, connect the phone to your PC before clicking this button and after picking a photo.


    Twitter: @bc3tech

    2012년 7월 23일 월요일 오후 4:01