Hello, relatively recently Vkontakte opened the Streaming API , but there is not much information on it 2 articles on Habré, and documentation with examples of use on Go. With getting the rules, I figured out:

 function GetRules($end_point, $stream_key) { $resp = 'https://'.$end_point.'/rules?key='.$stream_key; $resp = file_get_contents($resp); $resp = json_decode($resp, true); return $resp; } 

But with the addition of the rules, I did not understand, here is the documentation , and the article on the site . But I don’t understand how to send an add request with PHP and what is the link for the request? Please help.

  • Have you implemented everything? I'm going to do something like that for a company - traki_ivan

1 answer 1

I waited for an answer, and while I waited I figured it out. The question did not close because This is a relative new thing and there is little information on it. Here is the code

 function SetRules($end_point, $stream_key, $value, $tag) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://'.$end_point.'/rules?key='.$stream_key); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, '{"rule":{"value":"'.$value.'","tag":"'.$tag.'"}}'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $out = curl_exec($ch); curl_close($ch); echo $out; //здесь вам вернеться код 200/400 по желанию делайте return для проверки из-вне } 

Call example:

 SetRules('streaming.vk.com', '1234', 'test', '1'); 

streaming.vk.com - host to connect to the server.

1234 - access key. The key is perpetual and ceases to operate only after receiving a new key.

test - The value for the rule.

1 - Tag.