Hello, I can not get the username via vk_api
$pz = 'сайт.ру'; $url = "https://oauth.vk.com/access_token?client_id=******&client_secret=***&code=".$_GET['code']."&redirect_uri=".$pz; $ch = curl_init(); $timeout = 5; curl_setopt ($ch,CURLOPT_URL,$url); curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $file_contents = curl_exec($ch); curl_close($ch); $decode=json_decode($file_contents);
so I get access_token and user id later:
$url = "https://api.vk.com/method/users.get?uid=".$decode->user_id."&fields=uid,first_name,last_name,nickname,screen_name,sex,bdate,city,country,timezone,photo,photo_medium&access_token=".$decode->access_token; $ch = curl_init(); curl_setopt ($ch,CURLOPT_URL,$url); curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $file_contents = curl_exec($ch); curl_close($ch); $decode2 = json_decode($file_contents); echo $decode2->uid;
Here is what I get:
Notice: Undefined property: stdClass :: $ uid in /usr/home/lars/htdocs/cod.php on line 23
Although var_dump perfectly shows everything.
var_dump( $decode)
andvar_dump( $decode2)
? - Sergiks