J
J
Jony13372016-03-14 22:35:46
Classmates
Jony1337, 2016-03-14 22:35:46

How to get the gender of a person from a site?

How to get the gender of a person from a website

$client_id = 'xxxxxxxxxxxx'; // Application ID 
$public_key = 'xxxxxxxxxxxxxxxx'; // Публичный ключ приложения
$client_secret = 'xxxxxxxxxxxxxx'; // Секретный ключ приложения
$redirect_uri = 'http://site.ru/mm/rezultat.php'; // Ссылка на приложение 

$url = 'http://www.odnoklassniki.ru/oauth/authorize';
$params = array(
    'client_id'     => $client_id,
    'response_type' => 'code',
    'redirect_uri'  => $redirect_uri
);

if (isset($_GET['code'])) {
    $result = false;

    $params = array(
        'code' => $_GET['code'],
        'redirect_uri' => $redirect_uri,
        'grant_type' => 'authorization_code',
        'client_id' => $client_id,
        'client_secret' => $client_secret
    );

    $url = 'http://api.odnoklassniki.ru/oauth/token.do';

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($params)));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($curl);
    curl_close($curl);

    $tokenInfo = json_decode($result, true);

    if (isset($tokenInfo['access_token']) && isset($public_key)) {
        $sign = md5("application_key={$public_key}fields=uid,pic128x128,nameformat=jsonmethod=users.getCurrentUser" . md5("{$tokenInfo['access_token']}{$client_secret}"));
    
    

        $params = array(
            'method'          => 'users.getCurrentUser',
            'access_token'    => $tokenInfo['access_token'],
            'application_key' => $public_key,
            'format'          => 'json',
      'fields'          => 'uid,pic128x128,name',
            'sig'             => $sign
        );

        $userInfo = json_decode(file_get_contents('http://api.odnoklassniki.ru/fb.do' . '?' . urldecode(http_build_query($params))), true);
        if (isset($userInfo['uid'])) {
            $result = true;
        }
    }

}


if ($result) 
{

$urin = $userInfo['uid'];
$ur = $userInfo['pic128x128'];
$ne = $userInfo['name'];
}

having this
And how to get the photo link example ia124.mycdn.me/image?t=3&bid=805246478826&id=80376...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Ozhiganov, 2016-03-16
@vozhiganov

If the request succeeds, then gender is the gender field.
By default, fields with pictures pic_1, pic_2, pic_3 are returned. You can use them or request the ones you need in the fields parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question