S
S
Sergey2021-03-09 18:27:44
API
Sergey, 2021-03-09 18:27:44

How to attach a photo from another post via api?

Hello. I'm trying to publish a post in a group and attach a photo to it from another post of the same group (this is https://ok.ru/gorozhanin66/album/51173987778724/90... ) but I get a REQUEST error: errors.photo.not.available
Am I specifying the photo id incorrectly? Or you can not attach photos from other posts?

function ok_wall_post($message){
    $PCREpattern  =  '/\r\n|\r|\n/u';
    $message=preg_replace($PCREpattern, '\n', $message);
    $params = array(
        "application_key"=>OK_PUBLIC_KEY,
        "method"=>"mediatopic.post",
        "gid"=>OK_GROUP_ID,
        "type"=>"GROUP_THEME",
        "format"=>"json"
        );
    $attachment='{"media": [{"type": "text","text": "'.$message.'"},{"type": "photo","list": [{"photoId": "906927433124"}]}]}';
    $params['attachment']=$attachment;
    $sig = md5( arr_in_str( $params ) . OK_SESSION_KEY  );
    $params["access_token"] = OK_APP_TOKEN;
    $params["sig"] = $sig;
    $params['attachment']=urlencode($attachment);
    $result = json_decode( get_url( "https://api.ok.ru/fb.do", "POST", $params ), true );
    if ( isset( $result['error_code'] ) && $result['error_code'] == 5000 ) {
        get_url( "https://api.ok.ru/fb.do", "POST", $params );
        }
    return $result;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-03-26
@kolyadin_sa

Tech support response:

it is necessary to specify the group when forming the attachment, the group parameter.
{"photoId": "906927433124"} - right here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question