S
S
shogo2017-10-19 14:56:14
Classmates
shogo, 2017-10-19 14:56:14

How to use graph.user.messages POST method?

Friends, tell me how to correctly compose a request for this method, for writing a message from a group to a person.
What is written in the documentation does not reach me. Here is an example:
- there is a basic request https://api.ok.ru/graph/me/messages/chat:C3ecb9d02...
- where does the chat:C3ecb9d02a600 parameter come from (or where to get it)?
- how to add other parameters there:
{
"recipient":{
"user_id": "user:123456789012" /* Id of the recipient user in the format user:id or id*/
},
"message":{ /* Message content */
"text":"Hello" /* Message text */
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Konkin, 2017-10-19
@shogo

The method must be passed an access_token and the listed parameters in json format.
In php, the code will look something like this:
$ch = curl_init(' https://api.ok.ru/graph/me/messages/?access_token= '.$this->getGroupToken());
$params = [
'recipient' => [
'user_ids' => $userIds
],
'message' => [
'text' => $message
]
];
$payload = json_encode($params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question