#1 June 7, 2016 12:17pm

davidnewcomb
Member
Registered: March 17, 2016
Posts: 7

Using the Facebook API

I have been trying to get the BigTreeFacebookAPI working. I have filled in the appId and secret but I don't know what to write in order to call getPicture().

I am adding the code to my view file at bigtree2/templates/routed/news/detail.php

<?php
$c = new BigTreeFacebookAPI;
$u = $c->getUser();
$url = $u->getPicture();
?>

But all I get is an exception saying:
Fatal error: Uncaught exception 'Exception' with message 'This API is not connected.' in /Applications/XAMPP/xamppfiles/htdocs/my-app/bigtree2/core/inc/bigtree/apis/_oauth.base.php on line 252
Exception: This API is not connected. in /Applications/XAMPP/xamppfiles/htdocs/my-app/bigtree2/core/inc/bigtree/apis/_oauth.base.php on line 252
Call Stack

The documentation on this subject is a bit bare so can anyone help?

Offline

#2 June 7, 2016 2:36pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: Using the Facebook API

The Facebook API right now is a pretty barebones class that gets you setup to make calls to the graph API. You're getting the "This API is not connected." message because you haven't successfully retrieved an API token. Did you follow the full OAuth flow in the developer section giving your app access to your Facebook account?

Offline

#3 June 7, 2016 9:21pm

davidnewcomb
Member
Registered: March 17, 2016
Posts: 7

Re: Using the Facebook API

Haha, barebones - you're not kidding! But there was enough infrastructure to get me going. My Facebook AppId/Secret are fine and so I've spent most of the day looking at the code and concluded that it can't work!

Calling "new BigTreeFacebookAPI(false)" does not get an access token. It loads one from bigtree_settings and refreshes it (if needed). However, if the bigtree_settings doesn't contain an access_token (which it didn't on the first run) then the condition "if ($this->Settings["key"] && $this->Settings["secret"] && $this->Settings["token"]) {" in BigTreeOAuthAPIBase::__constructor() is never true and so Connected is never set to true. From that point everything returns "This API is not connected".

Basically if you have an access_token, even an expired one, you're ok; but if you don't have one there doesn't seem to be anyway of getting one!

I've added a check to BigTreeOAuthAPIBase's constructor which checks to see if Settings["token"] is set. If it isn't then it calls the OAuth API to get one, which is then saved to the bigtree_settings table and the world is wonderful again!

Now that it is working I've created BigTreeFacebookAlbum and BigTreeFacebookPicture. Just got a few bits and pieces to do but expect another branch push soon.

Probably need to add this to the bug tracking system at some point too. Hope I'm not messing up your roadmap!!

Offline

#4 June 8, 2016 8:18am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: Using the Facebook API

That's pretty strange that you didn't have an access token -- it should be set as part of the OAuth redirect in the Developer section.

We're happy to have contributions to the Facebook API -- I'm not much of a Facebook user and we haven't needed to do much with Facebook integrations in the past so it just hasn't seen much love! As far as the roadmap goes, there's semi-big changes to the APIs in 4.3 but it's very easy to port the service APIs from the 4.2 style BigTreeFacebookAlbum class names to BigTree\Facebook\Album class name style. Really we're just moving things into proper namespaces rather than using camelcase and using an autoloader that reads class locations from directories based on the namespace rather than storing an array full of class names and their locations (memory savings!).

Offline

#5 June 11, 2016 10:17am

davidnewcomb
Member
Registered: March 17, 2016
Posts: 7

Re: Using the Facebook API

I have got to the bottom of it now, you are right it does work.
It the absence of documentation, I had erroneously assumed that it worked like the last Facebook integration I did. It used an App Token which didn't need a return url as it didn't use OAuth. I couldn't understand why yours needed it, so I re-wrote the class to use App Token instead. While this is fine you only get App privileges and not the privileges of the person who logs in (User App Token). In my case that didn't matter but I can see why it would for other people. It didn't help that I couldn't find where to specify the ReturnUrl on the Facebook apps page, had to Google it in the end!

Just in response to your last comment, does that mean that all PHP classes will be in a separate file where the file is the class name because I was going to mention that as a 'developers' feature request. It would really make jumping around Eclipse a lot easier!

Offline

#6 June 11, 2016 9:47pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: Using the Facebook API

I feel you with the Facebook API. I went in to test it recently and the whole system was different. You have to add Facebook Login now if you want OAuth settings. I've updated the instructions for the next release. Google does the same thing -- I must have changed the instructions 6 times now in the 4.2 branch alone because of them moving stuff around in the API console.

As far as the new class setup, I would say checkout 4.3-devel on GitHub. It's still somewhat in flux but the /core/inc/classes/ directory should give you a good idea of the direction it's going. There's still backwards compatibility for the old class setup, though. BigTreeCMS / BigTreeAdmin / BigTreeAutoModule / BigTree all just make calls to the smaller class files.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.