[SOLVED] Access FB User Access Token from CB Connect

9 years 5 months ago - 9 years 3 months ago #254031 by timomer
Hi,

I wish to access the FB Access Token that is created for the user when logging in with CB Connect. I can see its stored in $access_token in /components/com_comprofiler/plugin/user/plug_cbconnect/hybridauth/Providers/Facebook.php

Is this stored in any CB Table?

Many thanks,
tim

Please Log in to join the conversation.

9 years 5 months ago #254119 by krileon
Replied by krileon on topic Access FB User Access Token from CB Connect
It's not stored anywhere except in the session. If you want access to it you need to call HybridAuth API.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

9 years 3 months ago #256600 by timomer
Replied by timomer on topic Access FB User Access Token from CB Connect
fyi, for anyone else having this question you can access the current sessions token with the following function:
Function getaccesstoken (){
	//gets current session fb access token
	$config = 'hybridauth/config.php';
	require_once( "hybridauth/Hybrid/Auth.php" );
	$hybridauth = new Hybrid_Auth( $config ); 
 
	// call Hybrid_Auth::getSessionData() to get stored data
	$hybridauth_session_data = $hybridauth->getSessionData();
	$deserialized_array = unserialize($hybridauth_session_data);
	//var_dump($deserialized_array);
	$a = $deserialized_array['hauth_session.facebook.token.access_token'];
	$a = split('["]', $a);

	return $a[1]; 	
}

this may not be the best way, I hacked it together over the last few days. fyi you need to download a copy of hybridauth, the config file just needs some basic settings.

-tim

Please Log in to join the conversation.

9 years 3 months ago #256630 by krileon
Replied by krileon on topic Access FB User Access Token from CB Connect
You don't need to hack anything together you can call it using CB Connect usage of HybridAuth API. Example as follows. HybridAuth is included with CB Connect so you don't need an external copy.

try {
	$hybrid		=	new cbconnectHybrid();
	$adapter	=	$hybrid->getAdapter( 'Facebook' );
	$token		=	$adapter->token( 'access_token' );
} catch ( Exception $e ) {}

The above should pull their access token if it's stored in the HybridAuth session. You can also directly access the adapter api using the following.

$token		=	$adapter->api->getAccessToken();

the above access the Facebook API library directly. I still have no idea why you need the token. You can make API calls using the above usage as well without ever needing to pass the token or make your own CURL calls as HybridAuth will handle that for you.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

9 years 3 months ago #256679 by timomer
Replied by timomer on topic Access FB User Access Token from CB Connect
Hi Krileon,

Thanks for the reply, yes im sure there is a better way to do this.

Unfortunately your examples bring back an empty $token

The reason I need the token is for another script on my site that pulls in other user information via my FB app (status updates, pictures, etc)

Please Log in to join the conversation.

9 years 3 months ago #256779 by krileon
Replied by krileon on topic Access FB User Access Token from CB Connect
You can also call getSessionData using the above APIs as well. I can't see how double including HybridAuth solves this. The session data and the cookies are still there and all the same. You're just loading the same PHP library twice. The only way this makes sense if your PHP script is external to Joomla, but even then you could just load the existing library in CB Connects folder.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.256 seconds

Facebook Twitter LinkedIn