none
Get Access Token

    Question

  • From:Visual C# General

    I want to get access token from vk.com WITH C# (Windows 8 METRO) but my code gives an error: CS0234.

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.Graphics.Display;
    using Windows.UI.ViewManagement;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    using Windows.Security.Authentication.Web;
    namespace App8
    {
      
        public sealed partial class MainPage : Page
        {
            public string access_token = null;
            public MainPage()
            {
                this.InitializeComponent();
                auth.Navigate(new Uri("https://oauth.vk.com/authorize?client_id=2720784&scope=2625424&redirect_uri=http://oauth.vk.com/blank.html&display=touch&response_type=token"));
            }
            void auth_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
            {
                GetAccessTokenFromUri(auth.Source.AbsoluteUri);
            }
            public void GetAccessTokenFromUri(string uri)
            {
                char[] excessChars = { '=', '&' };
                string[] response = uri.Split(excessChars);
    
                foreach (string s in response)
                {
                    if (s.Length == 63)
                        access_token = s;
                 
                }
                if (access_token != null)
                {
                    string destination = string.Format("/Menu.xaml?access_token={0}", access_token);
                    NavigationService.Navigate(new Uri(destination, UriKind.Relative));
                }
    
            }
          
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
            }
        }
    }

    Error on line:

    void auth_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)

    Plaease help me to correct the error. And SORRY FOR MY ENGLISH

    Friday, August 17, 2012 5:26 AM

All replies

  • Well, to begin with, you didn't declare the object "auth".

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, August 20, 2012 2:02 PM
    Moderator