1

Помогите найти скрипт php, авторизации через API одноклассники. Никак найти не могу...

Заранее благодарен за помощь!

2 ответа 2

2

Смотрите, знакомтесь

И вот ещё что есть:

<?php
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2.13) ' .
           'Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)';

$login = 'логин'; 
$password = 'пароль';
$ch = curl_init();

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, 'http://www.odnoklassniki.ru/dk?cmd=AnonymLogin&amp;st.cmd=anonymLogin&amp;tkn=941');

$post = array(
           'st.redirect' => '',
           'st.posted' => 'set',
           'st.email' => $login,
           'st.password' => $password,
           'st.screenSize' => '',
           'st.browserSize' => '',
                       'st.flashVer' => ''
       );

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$answer = curl_exec($ch);

// в ответ получили главную страницу
echo $answer;

curl_close($ch);
1
1

Вероятно как то так

    <?// this.php

$client_secret = 'секретный ключ приложения';
$clientId   ='идентификатор приложения';
$scope ='перечень прав доступа';

function send_post($post_url,$post_data)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $post_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, "coocie.dat");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "coocie.dat");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
};

if (empty($_GET['code'])) 
{
    header('location http://www.odnoklassniki.ru/oauth/authorize?client_id=$clientId&scope=$scope&response_type=code&redirect_uri=http://site/this.php');
}else{
    $url='http://api.odnoklassniki.ru/oauth/token.do';
    $data = array(
        'code '=>$_GET['code'],
        'redirect_uri'=>'http://site/this.php',
        'grant_type'=>'authorization_code',
        'client_id'=>$clientId,
        'client_secret'=>$client_secret
    )
    $data=json_decode(send_post($url,$data));
    $token = $data->access_token;
}

Подробнее про параметры смотрите по ссылке выше. Запросы к api делать передавая в параметрах полученный access_token

4
  • неделя некропостинга на хэшкоде ?
    – zb'
    10 авг 2013 в 8:22
  • @eicto сейчас увидел даты, и не понял как нашел этот пост...
    – naym
    10 авг 2013 в 8:24
  • Через текущие вопросы :) . Просто тема популярная и я решил, что негоже старой ссылке лежать. По делу: подскажите, чем по сути отличается Ваш ответ от того, который был? 10 авг 2013 в 9:25
  • 1
    @Михаил М в предыдущем требуется логин и пароль, а у меня по API)
    – naym
    10 авг 2013 в 9:33

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.