Привет всем. У меня проблема API авторизации вконтакте и вызове API методов
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
| static CookieContainer Cookies = new CookieContainer();
private static string sid;
public static string API_URL = "http://api.vkontakte.ru/api.php";
private static string POST(string url, string postData)
{
// Create a request using a URL that can receive a post.
System.Net.HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(url);
// Set the Method property of the request to POST.
request.Method = "POST";
request.AllowAutoRedirect = false;
// Create POST data and convert it to a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
try
{
// Write the data to the request strea
dataStream.Write(byteArray, 0, byteArray.Length);
}
finally
{
// Close the Stream object.
dataStream.Close();
}
// Get the response.
WebResponse response = request.GetResponse();
string headers = response.Headers.ToString();
Regex sidregex = new Regex("sid=([a-z0-9]+); exp");
Match ssid = sidregex.Match(headers);
sid = ssid.Groups[1].Value;
Cookie cook = new Cookie("remixsid", sid);
cook.Domain = "vkontakte.ru";
Cookies.Add(cook);
if (String.IsNullOrEmpty(sid))
{
}
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
try
{
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
return responseFromServer;
// Clean up the streams.
}
finally
{
reader.Close();
dataStream.Close();
response.Close();
}
}
static void Main(string[] args)
{
Console.ReadLine();
POST(@"http://vkontakte.ru/login.php", "m=1&email=имя@мило.com&pass=пароль");
Console.WriteLine(sid);
string token = POST(@"https://api.vkontakte.ru/oauth/access_token", "client_id=2308266&client_secret=секретыйключ");
Console.WriteLine(token);
Regex sidregex = new Regex("access_token\":\"([a-z0-9A-Z]+)");
Match ssid = sidregex.Match(token);
token = ssid.Groups[1].Value;
Console.ReadLine();
Console.WriteLine(POST(@"https://api.vkontakte.ru/method/isAppUser", "access_token=" + token + ""));
Console.WriteLine("Ok");
Console.ReadLine(); |
|
если у кого-то есть пример авторизации выложите пожалуйста