Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo('<pre>');
- // group id
- $group_id = '141035013';
- // access token
- $token = '4c1c5d3a8f2f1e2399349539f6003623b67fdd8ab30e88c2159242e82ee827a1c9bc0152140db3771d9a4';
- // params request
- $params = array(
- 'group_id' => $group_id,
- 'access_token' => $token,
- 'main_photo' => 1
- );
- // generic url
- $url = 'https://api.vk.com/method/photos.getMarketUploadServer?'.http_build_query($params);
- // generic options curl request
- $options = array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true
- );
- $response = request($options);
- // get url from response
- $url = $response['response']['upload_url'];
- // path to photo
- $path = 'upic.jpg';
- // generic post data
- $data = array('file' => '@'.$path);
- // generic options curl request
- $options = array(
- CURLOPT_URL => $url,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $data,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HEADERS => array('Content-Type: multipart/form-data')
- );
- // send curl request
- $response = request($options);
- // get photo id from response
- $photo = json_decode($response['photo'], true)[0]['photo'];
- // options url
- $params = array(
- 'group_id' => $group_id,
- 'access_token' => $token,
- 'photo' => $photo,
- 'server' => $response['server'],
- 'hash' => $response['hash'],
- 'crop_data' => $response['crop_data'],
- 'crop_hash' => $response['crop_hash']
- );
- // generic url
- $url = 'https://api.vk.com/method/photos.saveMarketPhoto?'.http_build_query($params);
- // options curl params
- $options = array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true
- );
- // send request
- $response = request($options);
- print_r($response);
- function request($options)
- {
- $ch = curl_init();
- curl_setopt_array($ch, $options);
- $response = curl_exec($ch);
- curl_close($ch);
- return json_decode($response, true);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement