Link to home
Start Free TrialLog in
Avatar of J N
J N

asked on

facebook api / sdk v4

Hi,

i am trying to add some of facebook functions to a website. i have looked through the developer documentation however i find it very choppy and difficult to follow.

i am trying to create a facebook object using the app id and app secret and use this to get the access_token. the information obtained will only for one set account. i would like to retrieve posts, information and post timeline posts. however im not sure what parts of the libraries i will even need

i have downloaded the sdk library here : https://github.com/facebook/facebook-php-sdk-v4

i believe i only need scripts from the src folder however i dont think i need to include all of them

any help is greatly appreciated
Avatar of J N
J N

ASKER

Currently i am trying this and i am getting the following error

function facebook_sm(){
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
 
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;

// init app with app id and secret
FacebookSession::setDefaultApplication( 'xxx','yyy' );


}

Open in new window


error:

Parse error: syntax error, unexpected 'use' (T_USE) in /home/content/21/10892721/html/bushbase/system/includes/functions_social.php on line 999

line 999:

use Facebook\FacebookSession;

if i remove
use Facebook\FacebookSession;
	use Facebook\FacebookRedirectLoginHelper;
	use Facebook\FacebookRequest;
	use Facebook\FacebookResponse;
	use Facebook\FacebookSDKException;
	use Facebook\FacebookRequestException;
	use Facebook\FacebookOtherException;
	use Facebook\FacebookAuthorizationException;
	use Facebook\GraphObject;
	use Facebook\GraphSessionInfo;

Open in new window


i do not get the error and then if i try and call the classes like so

$conn= new FacebookSession('xxx','yyy');

i get an error that the class does not exist

i look on the library that has class FacebookSession documented and there are errors in the script (may just be dreamweaver)

if i remove the namespace line in the scripts and run my function again i get the following as the conn var
FacebookSession Object
(
    [token:FacebookSession:private] => 468805886582817
    [signedRequestData:FacebookSession:private] => 277ffb54d927326812fdc93213dc4dfd
)

Open in new window


i no longer get any errors regarding the namespace

moving on i then try and get the profile using:
$user_profile = new FacebookRequest($conn, 'GET', '/me');
		$user_profile->execute()->getGraphObject(GraphUser::className());
		echo'<pre>';
		print_r($user_profile);

Open in new window


running this code i get the following error

Fatal error: Uncaught exception 'FacebookAuthorizationException' with message 'Invalid OAuth access token.' in /home/content/21/10892721/html/bushbase/system/libraries/facebook/FacebookRequestException.php:104 Stack trace: #0 /home/content/21/10892721/html/bushbase/system/libraries/facebook/FacebookRequest.php(291): FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 400) #1 /home/content/21/10892721/html/bushbase/system/includes/functions_social.php(1086): FacebookRequest->execute() #2 /home/content/21/10892721/html/bushbase/system/socialmedia.php(111): facebook_sm() #3 {main} thrown in /home/content/21/10892721/html/bushbase/system/libraries/facebook/FacebookRequestException.php on line 104

any help is greatly appreciated
Avatar of Scott Fell
Did you create an app on facebook yet?  https://developers.facebook.com/   Apps > Create New App  

Get your credentials.  

It has been a while since I have updated any of my facebook apps. They keep changing and I stopped trying to keep things up to date.  But I think this has been answered here already.  See if the thread below helps.  Most important thing is to create your app on facebook first and get your credentials and set up permissions for the app on facebook first.   Just doing that solves most issues.  

https://www.experts-exchange.com/questions/28101053/Facebook-Posts-on-Web-Page.html


https://developers.facebook.com/docs/graph-api/reference/v2.0/post/
This is only one piece of the puzzle (and it's a big research project).  It applies to the parse error in the first code snippet.

Please see this link, perhaps downvoted because the PHP comments are not supposed to be taken for pedestrian matters such as parse errors.  That said, it seems to identify the issue with use inside a function definition.
Avatar of J N

ASKER

Hi,

i think it is best to deal with facebook using cURL and http referrals instead of their SDK. ive had soo many issues with it that i dont think its worth diving into

thanks
Wow, a grade of "C" -- what did we do wrong here?  I think the E-E Grading Guidelines expect anyone to explain a grade like that.
http://support.experts-exchange.com/customer/portal/articles/481419
Avatar of J N

ASKER

Hi,
My reasoning is as follows:
1.  Took approx a month to get an response
2.  Padas response was something a work around and not specifically what i was looking for - i was already using http
3.  Ray you pointed me in another direction for more information which was somewhat useful
4. eventually, i came up with my own solution based on my own research
5. i though that both of you should be rewarded for your work but didnt help me come up with a solution ( i did it in the month that it took for the question to be answered and waited to see if the experts could come up with something i didnt see).

 i think based on my explanation the score is fair
A grade of "C" is inappropriate, especially when you've asked a question that requires a lot of research and has a lot of moving parts.
i came up with my own solution
The right thing to do is post your own solution and accept that as the answer.  Then anyone visiting in the future will gain the benefit of your research.
Avatar of J N

ASKER

Hi,

I created a new question to attack another area of the above question

i posted my solution in the top question part

https://www.experts-exchange.com/questions/28463740/facebook-wallpost-using-http-post.html
ASKER CERTIFIED SOLUTION
Avatar of J N
J N

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of J N

ASKER

my solution