-
-
Save anonymous/1bc57815ce915f17ca0af30da654ac78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
$client_id = ''; // ID приложения | |
$client_secret = ''; // Защищённый ключ | |
$redirect_uri = ''; // Адрес сайта | |
$scope = 'ads'; | |
$url = 'http://oauth.vk.com/authorize'; | |
$params = array( | |
'client_id' => $client_id, | |
'redirect_uri' => $redirect_uri, | |
'response_type' => 'code', | |
'scope' => $scope, | |
); | |
echo $link = '<p><a href="' . $url . '?' . urldecode(http_build_query($params)) . '">Аутентификация через ВКонтакте</a></p>'; | |
if (isset($_GET['code'])) { | |
$result = false; | |
$params = array( | |
'client_id' => $client_id, | |
'client_secret' => $client_secret, | |
'code' => $_GET['code'], | |
'redirect_uri' => $redirect_uri, | |
'scope' => $scope | |
); | |
$token = json_decode(file_get_contents('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true); | |
if (isset($token['access_token'])) { | |
$params = array( | |
'uids' => $token['user_id'], | |
'fields' => 'uid,first_name,last_name,screen_name,sex,bdate,photo_big', | |
'access_token' => $token['access_token'] | |
); | |
$data = array( | |
'access_token' => $token['access_token'], | |
'account_id' => 1602129376, | |
'data' => json_encode(array( | |
'ad_id' => 32266445, | |
'name' => '111', | |
)) | |
); | |
//echo '<hr>'.file_get_contents('https://api.vk.com/method/ads.getAdsLayout?access_token='.$token['access_token'].'&account_id=1602129376&campaign_ids=null&ad_ids=null'); | |
$url = 'https://api.vk.com/method/ads.updateAds?v=5.62'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'my user agent'); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); | |
$result = curl_exec($ch); | |
$curlInfo = curl_getinfo($ch); | |
curl_close($ch); | |
if ($curlInfo['http_code'] != 200) { | |
print "Error. Something went wrong. CODE: " . $curlInfo['http_code']; | |
print "\n $result"; | |
die(); | |
} | |
else { | |
$result = json_decode($result, true); | |
print_r($result); | |
} | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment