D
D
Decode Lorenzo2018-03-02 15:16:09
PHP
Decode Lorenzo, 2018-03-02 15:16:09

How to parse JSON array from VK API?

Good day. I would like to implement such a thing that analyzes the last 10 messages, and if the message is not checked - we read what the user sent, and if the message, say, is found in the "Base", or at the moment - the Array, then we chose one of the actions that is appropriate for this message.
Let's skip the complexity, I need to get an array via CURL, there is a blank, everything works out, I get a json object, and immediately decode it.

<?php
$token = 'TOKEN';

    $url = "https://api.vk.com/method/messages.get?out=0&offset=0&filtres=0&last_message_id=0&count=10&v=5.34&access_token=".$token."";

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
    $page = curl_exec($curl);

    $exited = json_decode($page, true);
?>

As a result I get this case:
5a993fd08cb84362317037.png
How can I get the parameters:
  1. Message text
  2. ID of the user who sent the message
  3. Dialog ID
  4. Message IDs

Help me please. I just need to write data to a variable, and nothing more. I'm just learning how to work with PHP, but so far it's hard.
PS Without File_Get_Contents

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tolmachev, 2018-03-02
@CACHE_GET_FIELD

Message text: ID of the user who sent the message Message IDs In general, read the documentation for the methods, everything is VERY detailed in the contact api. PS and yes, if you format the output of the code like this, you will be waiting for help for a very long time. I just know what the variables are and how they are called. Many in such a sheet of code will not even understand PPS and one more point that I did not pay attention to, but as pointed out by jasonOk , specify json_decode($page); , i.e. without true

U
Uno, 2018-03-02
@Noizefan

Uncertainty in this topic is caused by your lack of experience with JSON in principle.
For a better understanding, I recommend building some kind of array yourself and parsing it yourself.
In the world of APIs, the standard for issuing data for which is JSON, it is useful to be able to parse and assemble it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question