Yii Framework Forum: Yii Facebook connect - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Facebook connect Rate Topic: -----

#1 User is offline   Ashutosh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 21-December 11

Posted 04 January 2012 - 06:45 AM

Hello mates, I newbie to Yii.. I just started to learn Yii framework.

As part of practice, i implement facebook connect with Yii user management. It successfully implement, but the facebook id and other facebook data like session id and all that is in my url.. and another problem is even if i login with facebook successfully, i can't logined in my sample website..

How can i logged through facebook to my website?? Plz i need help..

Thanks in advance... :) :) :)
0

#2 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 04 January 2012 - 09:57 AM

View PostAshutosh, on 04 January 2012 - 06:45 AM, said:

Hello mates, I newbie to Yii.. I just started to learn Yii framework.

As part of practice, i implement facebook connect with Yii user management. It successfully implement, but the facebook id and other facebook data like session id and all that is in my url.. and another problem is even if i login with facebook successfully, i can't logined in my sample website..

How can i logged through facebook to my website?? Plz i need help..

Thanks in advance... :) :) :)


check this post for now My link

there are lots of post available here related to this issue.even you can also find content here.i have also implemented a facebook connect a year ago..:)
now i dont have sufficient time to explain about it but i am sure after reading above given link you will get good idea.:)
CodeSutra
0

#3 User is offline   Ashutosh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 21-December 11

Posted 09 January 2012 - 05:42 AM

View Postjayant, on 04 January 2012 - 09:57 AM, said:

check this post for now My link

there are lots of post available here related to this issue.even you can also find content here.i have also implemented a facebook connect a year ago..:)
now i dont have sufficient time to explain about it but i am sure after reading above given link you will get good idea.:)


hey thanks for helping me.. I trying some methods from ur link.. there are some problems occuring.. but will find way.. anyway.. thanks for help!! :D :)
0

#4 User is offline   Hardik Mistry 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 28-December 12
  • Location:Surat

Posted 31 December 2012 - 04:55 AM

View Postcodesutra, on 04 January 2012 - 09:57 AM, said:

check this post for now My link

there are lots of post available here related to this issue.even you can also find content here.i have also implemented a facebook connect a year ago..:)
now i dont have sufficient time to explain about it but i am sure after reading above given link you will get good idea.:)



PLzzz help me m new to yii and want to integrate facebook sign in i have downloaded extension from yiiframework.com named:facebook_connect but i dnt know how to do it working????you cn reply me @hardikmist@gmail.com
0

#5 User is offline   Hardik Mistry 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 28-December 12
  • Location:Surat

Posted 31 December 2012 - 04:58 AM

PLzzz help me m new to yii and want to integrate facebook sign in i have downloaded extension from yiiframework.com named:facebook_connect but i dnt know how to do it working????you cn reply me @hardikmist@gmail.com
0

#6 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 31 December 2012 - 08:44 AM

@Hardik Mistry

View PostHardik Mistry, on 31 December 2012 - 04:58 AM, said:

PLzzz help me m new to yii and want to integrate facebook sign in i have downloaded  extension from yiiframework.com named:facebook_connect but i dnt know how to do it working????you cn reply me @hardikmist@gmail.com

use this component.place this file in protected/components folder with Facebook.php name

<?php

class Facebook extends CApplicationComponent
{
	public $signedRequest;
	public $permissions;

	public $appId;
	public $appSecret;
	public $tabUrl;
	
	protected $curl;
	protected $me;

	/**
	 * Initializes this application component.
	 * This method is required by the IApplicationComponent interface.
	 */
	public function init()
	{
		parent::init();
		
		// Get the signed request
		if(isset($_REQUEST['signed_request']))
			$this->signedRequest = $this->parseSignedRequest($_REQUEST['signed_request']);

		// Initialize the cURL session
		$this->curl = curl_init();
		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
	}

	/**
	 * Session storage for the most utilised function
	 */
	public function getMe($params = array())
	{
		if(!$this->me)
			$this->me = $this->getCurl('me', $params);

		return $this->me;
	}

	/**
	 * Wrapper cURL function
	 */
	public function getCurl($query, $params = array(), $jsonDecode = true) {
		// Get the access token
		$accessToken = '';
		if(!isset($params['access_token']))
		{
			preg_match('/accessToken=[^&]+/', Yii::app()->user->model->session, $matches);
			$accessToken = str_replace('accessToken', 'access_token', $matches[0]);
		}

		// Form the query
		$paramString = '';
		foreach($params as $key => $val)
			$paramString .= $key.'='.rawurlencode($val).'&';

		$request = 'https://graph.facebook.com/'.$query.'?'.$paramString.$accessToken;

		// Execute the cURL session
		curl_setopt($this->curl, CURLOPT_URL, $request);
		$contents = curl_exec($this->curl);

		// Parse the response
		switch(curl_getinfo($this->curl, CURLINFO_HTTP_CODE)) {
			case 400: // Error
				return false;

			case 200: // Success
			default:
				return $jsonDecode ? json_decode($contents) : $contents;
		}
	}

	/**
	 * See http://developers.facebook.com/docs/authentication/signed_request/
	 */
	public function parseSignedRequest($signedRequest) {
		list($encodedSig, $payload) = explode('.', $signedRequest, 2);

		// Decode the data
		$sig = $this->base64UrlDecode($encodedSig);
		$data = json_decode($this->base64UrlDecode($payload), true);

		if(strtoupper($data['algorithm']) !== 'HMAC-SHA256')
		{
			error_log('Unknown algorithm. Expected HMAC-SHA256');
			return null;
		}

		// Check sig
		$expectedSig = hash_hmac('sha256', $payload, $this->appSecret, $raw = true);
		if($sig !== $expectedSig)
		{
			error_log('Bad Signed JSON signature!');
			return null;
		}

		return $data;
	}

	/**
	 * See http://developers.facebook.com/docs/authentication/signed_request/
	 */
	protected function base64UrlDecode($input)
	{
		return base64_decode(strtr($input, '-_', '+/'));
	}
	
	/**
	 * Clean-up
	 */
	public function __destruct() {
		curl_close($this->curl);
	}
}








Add some thing like this In your config/main.php components array like this:

  
                        ........
                        ........

                       'facebook'=>array(
			'class'=>'Facebook',
			'permissions'=>'',
			'appId'=>'xxxxxxxxxxxxxxx',
			'appSecret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
			'tabUrl'=>'http://www.facebook.com/appname/app_xxxxxxxxxxxxxxx',
		),
                        ........
                        ........



--hope this helps
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users