Open api vk.
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script src="http://vkontakte.ru/js/api/openapi.js?49" type="text/javascript"></script> <script type="text/javascript"> VK.init({ apiId: 3012101, onlyWidgets: true }); VK.Auth.login( null, VK.access.PHOTO | VK.access.FRIENDS); $(document).ready(function () { VK.Auth.getLoginStatus(function (response) { // берем его id var id = response.session.mid; VK.Api.call('wall.getPhotoUploadServer', {}, function (r) { $.post('upload.php', { url: r.response.upload_url }, function (data) { var mas = data.split(';'); var photo = mas[1].split('"'); //photo[3] var p = photo[3]; var hash1 = mas[2]; var serv = mas[0]; VK.Api.call('photos.saveWallPhoto', { server: serv, hash: hash1, photo: p }, function (d) { alert(d.src); }); }); }); //photoupload }); //getlogin }); //dw </script> </body> </html>
This is where the problem lies ... says undefined. What am I doing wrong?
VK.Api.call('photos.saveWallPhoto', { server: serv, hash: hash1, photo: p }, function (d) { alert(d.src); });
Here is the upload.php code
<?php if (isset($_POST["url"])) { $upload_url = $_POST["url"]; $post_params['photo'] = '@' . '0.png'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $upload_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); $result = curl_exec($ch); curl_close($ch); //var_dump($result); $result = json_decode($result); $mess = array( server => $result->server, photo => $result->photo, hash => $result->hash ); echo "$mess[server];$mess[photo];$mess[hash]"; } ?>
//var_dump($result);
? - Sergiks