H
H
Huligan1662019-01-31 21:47:58
PHP
Huligan166, 2019-01-31 21:47:58

Image doesn't load in mediatopic.post what's wrong?

<?php
// ID приложение
$appid = "xxx";
// Публичный ключ
$pub_k = "xxx";
// Секретный ключ
$sec_k = "xxx";
// Данные для авторизации
$access_token = "xxx";
$secret_session_key = "xxx";
 
// ID группы
$uid = "xxx";
//
//
 
 
$image_path = dirname(__FILE__).'/test.jpg';
$post_data = array("file1" => '@'.$image_path);
$sig = md5("application_key=".$pub_k."format=jsongid=".$uid."method=photosV2.getUploadUrlsession_key=".$access_token.$secret_session_key);
 
$url = file_get_contents("https://api.ok.ru/fb.do?application_key=".$pub_k."&format=json&gid=".$uid."&method=photosV2.getUploadUrl&session_key=".$access_token."&sig=".$sig."&session_key=".$access_token."");
$url1 = json_decode($url,true);
$ur = ($url1["upload_url"]);
$photo_ids = ($url1['photo_ids'][0]);
 
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ur);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = json_decode(curl_exec($ch),true);
 
print_r($result);
// токен фотографии
$token = ($result["photos"][$photo_ids]["token"]);
 
// id фотографии
echo $photo_ids;
echo $token;
 
 
 
 
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);
        $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;
}
$params = array(
    "application_key"=>$pub_k,
    "method"=>"mediatopic.post",
    "gid"=>$uid,//ID нашей группы
    "type"=>"GROUP_THEME",
    "attachment"=>'{"media": [{"type": "text","text": "test photo"},{"type": "photo","list":[{"id": "'.$token.'"}]}],"publishAt": "2019-02-01 19:09:13","onBehalfOfGroup": "true"}',//
    "format"=>"json"
);
$sig = md5(arInStr($params).md5("{$access_token}{$sec_k}"));
$params["access_token"]=$access_token;
$params["sig"]=$sig;
 
$result_post = json_decode(getUrl("https://api.ok.ru/fb.do", "POST", $params), true);
 
if (isset($result_post['error_code']) && $result_post['error_code'] == 5000) {
    getUrl("https://api.ok.ru/fb.do", "POST", $params);
}
 
?>

A post is published either without a photo or not published at all, what could be the error?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question