L
L
likvp2016-02-11 12:41:15
PHP
likvp, 2016-02-11 12:41:15

How to make an entry in the ok.ru group using php?

I found the script, here is the execution part:
function getUrl($url, $type="GET", $params=array(), $timeout=30) {
if ($ch = curl_init()) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
if ($type == "POST") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode(http_build_query($params)));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Bot ( http://bazarbratsk.ru) ');
$data = curl_exec($ch);
curl_close($ch);
return $data;
} else {
return "{}";
}
}
function arInStr($array) {
ksort($array);
$string = "";
foreach($array as $key=>$val) {
if (is_array($val)) {
$string .= $key."=".arInStr($val);
} else {
$string .= $key."=".$val;
}
}
return $string;
}
$ok_access_token = "tkn14Xrkj17NtyTSLDM*********uP1X5CWzjxydP";//Our eternal token
$ok_private_key = "8BAD5FF7****34CD79F4";//Application secret key
$ok_public_key = "CBAKHPD***"; //Application public key
$params = array(
"application_key"=>$ok_public_key,
"gid"=>"52987290124455",//our group ID
"type"=>"GROUP_THEME",
"attachment"=>'{"media": [{"type": "link","url": " vp43 .ru "}]}',
"format"=>"json"
);
$sig = md5(arInStr($params).md5("{$ok_access_token}{$ok_private_key}"));
$params["access_token"]=$ok_access_token;
$params["sig"]=$sig;
$result = json_decode(getUrl(" https://api.ok.ru/fb.do ", "POST", $params), true);
//If the parser couldn't open our link (sometimes it does it on the second try),
then send again if (isset($result['error_code']) && $result['error_code'] == 5000) {
getUrl(" https://api.ok.ru/fb.do ", "POST" , $params);
}
print_r($result);
I recreated the token, and the following message began to come:
Array ( [error_code] => 456 [error_msg] => GROUP_RESTRICTION : errors.group.cannot_create_topic [error_data] => )

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Max, 2016-02-11
@AloneCoder

https://apiok.ru/wiki/display/api/mediatopic.post+en
The method is closed for use by default.
Posting to a group only requires the GROUP_CONTENT right.

L
likvp, 2016-02-11
@likvp

cc3b0fe27cd24a0f9fb2fe9daa11b716.JPG5ba1d1c7cccf469aa4b3064a8206b00a.JPG

V
Vjacheslav Kanivetc, 2016-02-11
@Vjaka

Judging by the error - the user does not have the rights to create in the group, although the screenshot above says that the rights to post are given to everyone .. There remains the option that the eternal token does not give this right.
It is recommended to write to [email protected] and see the problem in detail in a particular case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question