Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > Интернет и сети
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 16.03.2016, 10:51
MAPODEP MAPODEP вне форума
Прохожий
 
Регистрация: 16.03.2016
Сообщения: 1
Версия Delphi: Delphi XE7
Репутация: 10
По умолчанию Delphi отправка сообщений в ВК

не знаю что уже и делать, отправляются сообщения либо не форматированный текст, либо вообще не отправляются
1. в таком виде, пост нормально отображается
response:= send ('GET','https://api.vk.com/method/wall.post?owner_id=ИД_пользователя&message='+UrlEn code(AnsiToUTF8('Салат "Лисичка"'+#10#13+''+#10#13+'Ингредиенты:'+#10#13+ '2 филе куриной грудки'+#10#13+'3 маринованных огурца'+#10#13+'200 гр. корейской моркови'+#10#13+'200 гр. сыра'+#10#13+'2 зубчика чеснока'+#10#13+'майонез'+#10#13+'зелень'+#10#13+' '+#10#13+'Приготовление:'+#10#13+'1. Филе отвариваем в подсоленной воде,затем нарезаем полосочками (или разбираем руками на волокна).'+#10#13+'2. Огурцы также нарезаем полосочками,сыр на крупной терке.'+#10#13+'3. Смешиваем филе.сыр,огурцы и морковь,добавляем выдавленный через пресс чеснок и заправляем майонезом.'))+'&access_token='+token);

2. А в таком не выходит
response:= send ('GET','https://api.vk.com/method/wall.post...iToUTF8(Edit3.Text))+'&access_token='+ token);



весь код:

Код:
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
unit Unit1;
 
interface
 
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,httpsend,ssl_openssl,lib,
Vcl.ComCtrls, System.StrUtils, Xml.xmldom, Xml.XMLIntf, Xml.XMLDoc,
Vcl.Buttons, Vcl.Grids, FireDAC.Stan.StorageXML, ComObj, msxml, Vcl.ExtCtrls,
NiceGrid;
 
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Button3: TButton;
Edit3: TEdit;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
ListBox1: TListBox;
BitBtn1: TBitBtn;
XMLDocument1: TXMLDocument;
StringGrid1: TNiceGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
 
procedure Button5Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
 
private
{ Private declarations }
public
email,pass,response,msg,userid:string;
{ Public declarations }
end;
 
var
Form1: TForm1;
token:string;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i, n: integer;
s,t:string;
Nodes: IXMLDomNodeList;
doc :IXMLDOMDocument;
begin
Doc := CreateComObject(CLASS_DOMDocument) as IXMLDOMDocument;
Doc.load('data.xml');
Nodes := Doc.selectNodes('//post/*');
n:=0;
for i:=0 to Nodes.length-1 do
begin
if Nodes.nodeName='text' then
begin
n:=n+1;
 
s:=(Format('%s', [Nodes.text]));
// showmessage (s);
t:=StringReplace( s, #10, #39'+#10#13+'#39, [rfReplaceAll]);
StringGrid1.Cells[0,n]:=#39 +t+ #39 ;
// showmessage (StringGrid1.Cells[0,n]);
StringGrid1.RowCount:=StringGrid1.RowCount+1;
end;
 
if Nodes.nodeName='photo_130' then
begin
StringGrid1.Cells[1,n]:=(Format('%s', [Nodes.text]));
end;
 
if Nodes.nodeName='comments' then
begin
StringGrid1.Cells[2,n]:=(Format('%s', [Nodes.text]));
end;
if Nodes.nodeName='likes' then
begin
StringGrid1.Cells[3,n]:=(Format('%s', [Nodes.text]));
end;
if Nodes.nodeName='reposts' then
begin
StringGrid1.Cells[4,n]:=(Format('%s', [Nodes.text]));
end;
end;
 
//Srv:=Nil;
Doc := nil;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
s2:string;
begin
email:=Edit1.Text;
pass:=Edit2.Text;
response:=send('GET','https://oauth.vk.com/token?grant_ty...assword='+pass+'&captcha_key=&captcha_sid=');
 
msg:=response;
if Pos('token',response) <> 0 then
begin
s2:=copy(response, pos('access_token":"', response), pos('","expires_in', response)-3);
delete(s2, 1, 15);
token:=s2;
Memo1.Lines.Add(msg);
msg:=token;
 
userid:=s2;
s2:=Copy(response,Pos('user_id":',response),Pos('}',response));
Delete(s2,1,9);
Delete(s2,Pos('}',s2),1);
userid:=s2;
Memo1.Lines.Add(msg);
msg:=userid;
Memo1.lines.add (msg);
 
 
end else
begin
memo1.lines.add('Error');
end;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
//showmessage(msg);
response:=send('GET','https://api.vk.com/method/friends.get?uid=ИД_пользователя&access_token='+token);
 
 
msg:=response;
Memo1.Lines.Add(msg)
end;
function UrlEncode(Str: ansistring): ansistring;
 
function CharToHex(Ch: ansiChar): Integer;
asm
and eax, 0FFh
mov ah, al
shr al, 4
and ah, 00fh
cmp al, 00ah
jl @@10
sub al, 00ah
add al, 041h
jmp @@20
@@10:
add al, 030h
@@20:
cmp ah, 00ah
jl @@30
sub ah, 00ah
add ah, 041h
jmp @@40
@@30:
add ah, 030h
@@40:
shl eax, 8
mov al, '%'
end;
 
var
i, Len: Integer;
Ch: ansiChar;
N: Integer;
P: PansiChar;
begin
Result := '';
Len := Length(Str);
P := PansiChar(@N);
for i := 1 to Len do
begin
Ch := Str;
if Ch in ['0'..'9', 'A'..'Z', 'a'..'z', '_'] then
Result := Result + Ch
else
begin
if Ch = ' ' then
Result := Result + '+'
else
begin
N := CharToHex(Ch);
Result := Result + P;
end;
end;
end;
end;
 
procedure TForm1.Button3Click(Sender: TObject);
begin
 
response:= send ('GET','https://api.vk.com/method/wall.post?owner_id=ИД_пользователя&message='+UrlEncode(AnsiToUTF8('Салат "Лисичка"'+#10#13+''+#10#13+'Ингредиенты:'+#10#13+'2 филе куриной грудки'+#10#13+'3 маринованных огурца'+#10#13+'200 гр. корейской моркови'+#10#13+'200 гр. сыра'+#10#13+'2 зубчика чеснока'+#10#13+'майонез'+#10#13+'зелень'+#10#13+''+#10#13+'Приготовление:'+#10#13+'1. Филе отвариваем в подсоленной воде,затем нарезаем полосочками (или разбираем руками на волокна).'+#10#13+'2. Огурцы также нарезаем полосочками,сыр на крупной терке.'+#10#13+'3. Смешиваем филе.сыр,огурцы и морковь,добавляем выдавленный через пресс чеснок и заправляем майонезом.'))+'&access_token='+token);
msg:=response;
if Pos('post_id',response)<> 0 then
begin
Memo1.Lines.Clear;
Memo1.Lines.Add('Пост отправлен'+msg);
end else
begin
Memo1.Lines.Add('Вы не авторизованы'+msg);
end;
end;
 
 
 
procedure TForm1.Button5Click(Sender: TObject);
begin
end;
 
procedure TForm1.Button7Click(Sender: TObject);
begin
end;
 
end.

Последний раз редактировалось Aristarh Dark, 16.03.2016 в 10:54.
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 11:21.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025