forked from niken0793/RxBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook.cpp
More file actions
112 lines (87 loc) · 3.17 KB
/
facebook.cpp
File metadata and controls
112 lines (87 loc) · 3.17 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "includes.h"
#pragma comment(lib,"wininet.lib")
int String2Char(string s, char a[])
{
int n = s.size();
int i = 0;
while(a[i]=s[i])
i++;
return 1;
}
FbStatus GetFBStatuses(string paramId, string paramField,string paramToken)
{
HINTERNET hopen, hconnect, hrequest;
string accesstoken = paramToken;
int n = accesstoken.size();
string version = "/v2.1";
string id = paramId;
string edge ="/statuses";
string field = paramField;
char chUrlRequset [400];
FbStatus t;
string urlRequest = version+id+edge+field+"&"+accesstoken;
String2Char(urlRequest,chUrlRequset);
hopen = InternetOpen("HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hconnect = InternetConnect(hopen,GRAPH_FB,INTERNET_DEFAULT_HTTPS_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
//hrequest= HttpOpenRequestA(hconnect,"GET","/v2.1/me/statuses?fields=message&limit=2&access_token=CAAVUMKQz7ZB0BANtlRFjMPvzH2PQ2We0Xy6tyd8iAAnSMMHZCduQHQMGZAln4PWOQO6CPFnYT4LVpQJ2TBay7vIR268fuq3jVONE5Hteq05GQA8QlBapz3ZAWmQdmu43giQytttLwpCAphqZCcztAwrlLX3kpc2hm4tBCYmTn7xkRHPoEazE1Nb2XSXQAnYDRZCK6sNixcj7nDni2QN4am" ,"HTTP/1.1",NULL, NULL,INTERNET_FLAG_SECURE , 0);
hrequest= HttpOpenRequest(hconnect,"GET",chUrlRequset,"HTTP/1.1",NULL, NULL,INTERNET_FLAG_SECURE , 0);
printf("FB Sending\n");
if(HttpSendRequest(hrequest,NULL,NULL,NULL,0)){
printf("FB Success\n");
CHAR szBuffer[2048];
DWORD dwRead=0;
printf("FB Reading status\n");
while(InternetReadFile(hrequest, szBuffer, sizeof(szBuffer)-1, &dwRead) && dwRead)
{
szBuffer[dwRead] = 0;
//printf(szBuffer);
dwRead=0;
}
printf("FB Finish Reading\n");
cJSON *root = cJSON_Parse(szBuffer);
cJSON* arr = cJSON_GetObjectItem(root,"data");
//printf("\n\n");
if(cJSON_GetArraySize(arr)>0)
{
cJSON *subitem = cJSON_GetArrayItem(arr,0);
//printf("%s\n",cJSON_GetObjectItem(subitem,"message")->valuestring);
t.message = cJSON_GetObjectItem(subitem,"message")->valuestring;
t.Id = cJSON_GetObjectItem(subitem,"id")->valuestring;
printf("FB returning message\n");
return t;
}
}
else
{
printf("Failed\n");
return t;
}
//InternetCloseHandle(hrequest);
//InternetCloseHandle(hconnect);
//InternetCloseHandle(hopen);
}
int UpStatusFb(string paramId, string paramMessage, string paramToken)
{
HINTERNET hopen, hconnect, hrequest;
string accesstoken = paramToken;
int n = accesstoken.size();
string version = "/v2.1";
string id = paramId;
string edge ="/comments";
char chUrlRequset [400];
string urlRequest = version+"/"+id+edge+"?"+accesstoken;
String2Char(urlRequest,chUrlRequset);
char headers[]="Content-Type: application/x-www-form-urlencoded";
char formdata[300];
String2Char("message="+paramMessage,formdata);
hopen = InternetOpenA("HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hconnect = InternetConnectA(hopen,GRAPH_FB,INTERNET_DEFAULT_HTTPS_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
hrequest= HttpOpenRequestA(hconnect,"POST",chUrlRequset,"HTTP/1.1",NULL, NULL,INTERNET_FLAG_SECURE , 0);
if(HttpSendRequestA(hrequest,headers,strlen(headers),formdata,strlen(formdata))) {
//printf("Success\n");
}
InternetCloseHandle(hrequest);
InternetCloseHandle(hconnect);
InternetCloseHandle(hopen);
return 1;
}