Answer the question
In order to leave comments, you need to log in
How to get data from VK API using wall.get method?
Hey!
Guys, I created a request, I want to use JSONP, because I am writing a jQueryMobile application.
The request looks like
https://api.vk.com/method/wall.get?v=5.25&filter=owner&domain=' + domain + '&count=' + count + '&callback=GetWallVK
$url = "http://api.vk.com/method/wall.get?owner_id=$owner_id&count=90";
$response = file_get_contents($url);
$wall = json_decode($response);
for ($i = 1; $i<=count($wall->response)-1; $i++) {
$wall->response[$i]->text = preg_replace("#—#", '', $wall->response[$i]->text);
$wall->response[$i]->text = html_entity_decode($wall->response[$i]->text, null, 'utf-8');
$newItem = $feed->createNewItem();
$title = explode('<br>',$wall->response[$i]->text);
$title = $title[0];
$title = (mb_strlen($title, 'utf-8')<=100) ? $title : mb_substr($title,0,100,'utf-8').'...';
//echo $wall->response[$i]->id."\t".$title."\t".$wall->response[$i]->text."\n";
$newItem->setTitle($title);
$newItem->setLink("http://vk.com/wall{$owner_id}_{$wall->response[$i]->id}");
$newItem->setDate($wall->response[$i]->date);
$description = $wall->response[$i]->text;
if (isset($wall->response[$i]->attachments)) {
foreach ($wall->response[$i]->attachments as $attachment) {
switch ($attachment->type) {
case 'photo': {
$description .= "<br><img src='{$attachment->photo->src_big}'/>";
break;
}
case 'audio': {
$description .= "<br><a href='http://vk.com/wall{$owner_id}_{$wall->response[$i]->id}'>{$attachment->audio->performer} – {$attachment->audio->title}</a>";
break;
}
case 'doc': {
$description .= "<br><a href='{$attachment->doc->url}'>{$attachment->doc->title}</a>";
break;
}
case 'link': {
$description .= "<br><a href='{$attachment->link->url}'>{$attachment->link->title}</a>";
break;
}
case 'video': {
$description .= "<br><a href='http://vk.com/video{$attachment->video->owner_id}_{$attachment->video->vid}'><img src='{$attachment->video->image_big}'/></a>";
break;
}
}
}
}
$newItem->setDescription($description);
$newItem->addElement('guid', $wall->response[$i]->id);
$feed->addItem($newItem);
}
Answer the question
In order to leave comments, you need to log in
Everything is simple there:
I sent a request, received a response, the response has a clear structured form in JSON. It must be parsed into components by levels, and then parse the data from the necessary variables.
Here is a simple example of how to parse a response in python -
response = vk.wall.get(owner_id=man_id, post_id=a, count=1, sort='desc', offset=0)
ts = str(response['items'][0]['date'])
print(ts)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question