<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
	<channel>
		<title>cotonti.com : hybridauth и одноклассники</title>
		<link>https://www.cotonti.com</link>
		<description>Last topic posts</description>
		<generator>Cotonti</generator>
		<language>en</language>
		<pubDate>Sat, 04 Apr 2026 08:44:09 -0000</pubDate>

		<item>
			<title>foxss</title>
			<description><![CDATA[<p>в общем вотЬ рабочий odnoklassniki.php</p>

<p>но если вам надо получать больше чем uid и url то раскоментируйте нужное и подайте запрос в администрацию ОК на доступ.</p>

<pre class="brush:php;">
&lt;?php
/* HybridAuth
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
* (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
*/
/**
 * Hybrid_Providers_Odnoklassniki provider adapter based on OAuth2 protocol
 */
class Hybrid_Providers_Odnoklassniki extends Hybrid_Provider_Model_OAuth2
{
	/**
	* ID wrappers initializer
	* инициализатор индификаторов ID
	*/
	function initialize()
	{
		parent::initialize();
		// Provider apis end-points
		// 
		$this-&gt;api-&gt;api_base_url    = "http://api.ok.ru/fb.do";
		$this-&gt;api-&gt;authorize_url   = "http://connect.ok.ru/oauth/authorize";
		$this-&gt;api-&gt;token_url       = "http://api.odnoklassniki.ru/oauth/token.do";
		$this-&gt;api-&gt;sign_token_name = "access_token";
	}
	
// {"access_token":"значение","refresh_token":"значение","expires_in":"1800"}
	private function request($url, $params=false, $type="GET")
	{
		Hybrid_Logger::info("Enter OAuth2Client::request($url)");
		Hybrid_Logger::debug("OAuth2Client::request(). dump request params: ", serialize($params));
		if ($type === "GET"){
			echo $url = $url . (strpos($url, '?') ? '&amp;' : '?') . http_build_query($params, '', '&amp;');
		}
		$this-&gt;http_info = array();
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL            , $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
		curl_setopt($ch, CURLOPT_TIMEOUT        , $this-&gt;api-&gt;curl_time_out);
		curl_setopt($ch, CURLOPT_USERAGENT      , $this-&gt;api-&gt;curl_useragent);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , $this-&gt;api-&gt;curl_connect_time_out);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , $this-&gt;api-&gt;curl_ssl_verifypeer);
		curl_setopt($ch, CURLOPT_HTTPHEADER     , $this-&gt;api-&gt;curl_header);
		if ($this-&gt;api-&gt;curl_proxy) {
			curl_setopt($ch, CURLOPT_PROXY  , $this-&gt;api-&gt;curl_proxy);
		}
		if ($type === "POST") {
			curl_setopt($ch, CURLOPT_POST, 1);
			if ($params) curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
		}
		$response = curl_exec($ch);
		Hybrid_Logger::debug("OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch)));
		Hybrid_Logger::debug("OAuth2Client::request(). dump request result: ", serialize($response));
		$this-&gt;http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		$this-&gt;http_info = array_merge($this-&gt;http_info, curl_getinfo($ch));
		curl_close ($ch);
		return $response;
	//	echo $response;
	//	exit();
// echo $response выдает {"access_token":"значение","refresh_token":"значение","expires_in":"1800"}
	}
	
//парсер ответа
	private function parseRequestResult($result)
	{
		if (json_decode($result)) return json_decode($result);
		parse_str($result, $output);
		$result = new StdClass();
		foreach ($output as $k =&gt; $v) {
			$result-&gt;$k = $v;
		}
		return $result;
	}
	//first
	function authodnoklass($code)
	{
		$params = array(
			"client_id"     =&gt; $this-&gt;api-&gt;client_id,
			"client_secret" =&gt; $this-&gt;api-&gt;client_secret,
			"grant_type"    =&gt; "authorization_code",
			"redirect_uri"  =&gt; $this-&gt;api-&gt;redirect_uri,
			"code"          =&gt; $code
		);
		$response = $this-&gt;request($this-&gt;api-&gt;token_url, http_build_query($params, '', '&amp;'), $this-&gt;api-&gt;curl_authenticate_method);
// {"access_token":"значение","refresh_token":"значение","expires_in":"1800"}
		$response = $this-&gt;parseRequestResult($response);
// нет реакции
		if (!$response || !isset($response-&gt;access_token)) {
			throw new Exception("The Authorization Service has return: " . $response-&gt;error);
		}
		if (isset($response-&gt;access_token)) $this-&gt;api-&gt;access_token          = $response-&gt;access_token;
		if (isset($response-&gt;refresh_token)) $this-&gt;api-&gt;refresh_token        = $response-&gt;refresh_token;
		if (isset($response-&gt;expires_in)) $this-&gt;api-&gt;access_token_expires_in = $response-&gt;expires_in;
		// Calculate when the access token expire.
		// At this moment Odnoklassniki does not return expire time in response.
		// 30 minutes expire time staten in dev docs http://apiok.ru/wiki/pages/viewpage.action?pageId=42476652
		if (isset($response-&gt;expires_in)) {
			$this-&gt;api-&gt;access_token_expires_at = time() + $response-&gt;expires_in;
		}
		else {
			$this-&gt;api-&gt;access_token_expires_at = time() + 1800;
		}
		return $response;
	}
	function loginFinish()
	{
		$error = (array_key_exists('error',$_REQUEST))?$_REQUEST['error']:"";
		// Check for errors
		if ($error) {
			throw new Exception("Authentication failed! {$this-&gt;providerId} returned an error: $error", 5);
		}
		// Try to authenticate user
		$code = (array_key_exists('code',$_REQUEST))?$_REQUEST['code']:"";
// выдает значение code 
		try {
			$response = $this-&gt;authodnoklass($code);
		}
		catch (Exception $e) {
			throw new Exception("User profile request failed! {$this-&gt;providerId} returned an error: $e-&gt;getMessage() ", 6);
		}
		// Check if authenticated
		if (!$this-&gt;api-&gt;access_token) {
			throw new Exception("Authentication failed! {$this-&gt;providerId} returned an invalid access token.", 5);
		}
		// Store tokens
		$this-&gt;token("access_token" , $this-&gt;api-&gt;access_token);
		$this-&gt;token("refresh_token", $this-&gt;api-&gt;refresh_token);
		$this-&gt;token("expires_in"   , $this-&gt;api-&gt;access_token_expires_in);
		$this-&gt;token("expires_at"   , $this-&gt;api-&gt;access_token_expires_at);
		// Set user connected locally
		$this-&gt;setUserConnected();
	}
	/**
	* Load the user profile.
	*/
	function getUserProfile()
	{
		// Set fields you want to get from OK user profile.
		// @see https://apiok.ru/wiki/display/api/users.getCurrentUser+ru
		// @see https://apiok.ru/wiki/display/api/fields+ru

		$fields = "uid,url_profile";
		//,LOCALE,FIRST_NAME,LAST_NAME,NAME,GENDER,AGE,BIRTHDAY,HAS_EMAIL,EMAIL,CURRENT_STATUS,CURRENT_STATUS_ID,CURRENT_STATUS_DATE,ONLINE,PHOTO_ID,PIC190X190,PIC640X480,LOCATION";
		// Signature
		$sig = md5('application_key=' . $this-&gt;config['keys']['key'] . 'fields=' . $fields .'method=users.getCurrentUser' . md5($this-&gt;api-&gt;access_token . $this-&gt;api-&gt;client_secret));
//sig = 0e813f9ed55c8b0d8ea47c2ad1f791be
		// Signed request
		$response = $this-&gt;api-&gt;api('?application_key=' . $this-&gt;config['keys']['key'] . '&amp;fields=' . $fields .'&amp;method=users.getCurrentUser&amp;sig=' . $sig);
		if (!isset($response-&gt;uid)) {
			throw new Exception("User profile request failed! {$this-&gt;providerId} returned an invalid response.", 6);
		}
		$this-&gt;user-&gt;profile-&gt;identifier    = (property_exists($response,'uid'))?$response-&gt;uid:"";
		$this-&gt;user-&gt;profile-&gt;firstName     = (property_exists($response,'first_name'))?$response-&gt;first_name:"";
		$this-&gt;user-&gt;profile-&gt;lastName      = (property_exists($response,'last_name'))?$response-&gt;last_name:"";
		$this-&gt;user-&gt;profile-&gt;displayName   = (property_exists($response,'name'))?$response-&gt;name:"";
		// Get better size of user avatar
		$this-&gt;user-&gt;profile-&gt;photoURL      = (property_exists($response,'pic190x190'))?$response-&gt;pic190x190:"";
		$this-&gt;user-&gt;profile-&gt;photoBIG      = (property_exists($response,'pic640x480'))?$response-&gt;pic640x480:"";
		$this-&gt;user-&gt;profile-&gt;profileURL    = (property_exists($response,'uid'))?"https://ok.ru/profile/" . $response-&gt;uid:"";
		$this-&gt;user-&gt;profile-&gt;gender        = (property_exists($response,'gender'))?$response-&gt;gender:"";
		$this-&gt;user-&gt;profile-&gt;email         = (property_exists($response,'email'))?$response-&gt;email:"";
		$this-&gt;user-&gt;profile-&gt;emailVerified = (property_exists($response,'email'))?$response-&gt;email:"";
		if (property_exists($response, 'birthday')) {
			list($birthday_year, $birthday_month, $birthday_day) = explode('-', $response-&gt;birthday);
			$this-&gt;user-&gt;profile-&gt;birthDay   = (int) $birthday_day;
			$this-&gt;user-&gt;profile-&gt;birthMonth = (int) $birthday_month;
			$this-&gt;user-&gt;profile-&gt;birthYear  = (int) $birthday_year;
		}
		return $this-&gt;user-&gt;profile;
	}
}</pre>
]]></description>
			<pubDate>Sun, 13 Aug 2017 23:07:53 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=8441&d=0#post42995]]></link>
		</item>
	</channel>
</rss>