× Joomla Facebook Connect support forum

Topic-icon HOW DO I TRIGGER AN OPENGRAPH ACTION?

Support Specialist
12 years 2 months ago #19847 by alzander
Glad we could help! It's not really documented simply because it's not something most users will be doing. Talking about namespace:action tags in the OG documentation would confuse 99 people for every 1 it helped. Until we have the full system to do everything, including pushing the actions, it's worth leaving it undocumented :)

Baby steps.

Best of luck,
Alex
The topic has been locked.
12 years 1 month ago #20978 by ferm
@learnthrusong so did you figure out how to trigger the actions? I got all the verbs and the og:types set on my flypages. Now only need to trigger the action to timeline. Completely at a loss there, is it curl I am supposed to use with the code I got from FB?

Thanks for any help,
The topic has been locked.
Active Subscriptions:

None
12 years 2 weeks ago #21574 by learnthrusong
Hi Alzander,

OK, I have managed to post a 'listen' action to my application by adding some javascript to some of my existing playlist/player events and listeners. This is mostly working fine except that, when I'm on an album page, I need to be able to do some database calls to grab some further information about the item that's being played - for example, what format it is, whether its a video or audio and whether it's a tutorial, project or album for instance.

This is impossible to achieve with js alone. This means I can't pipe in the additional fb object parameters that I require in my app and results in incomplete information.

My workaround for this is to revert to using the php-sdk - or rather, JFBC's implementation of it. I know that this in theory, using the standard php sdk, can be achieved using
$facebook->api('https://graph.facebook.com/me/learnthrusong:listen?song=https://www.learnthrusong.co.uk/index.php?option=com_muscol&view=song&id=164','POST');

However, I'm unsure how to call on the equivalent method within my implementation of JFBC. Here's what I have so far....

I have a custom php file to which, I will pass in the id of the song using javascript like;
var req = new Request({
  method: 'get',
  url: postObj // this is the url to the php file I use to process that includes the id of the song
}).send();

Using php, I then do some checking/processing to gather the additional information I require to make the graph call to my FB application. After doing my basic checks, I then wish to use the same type of graph call mentioned above. As I don't have the 'standard' fb php-sdk loaded, I've changed the call a little, in an attempt to call on JFBC's implementation of the sdk as follows;
// presumably I need to include this file, right? 
require_once JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php';
$fbLibrary = JFBConnectFacebookLibrary::getInstance(); 
$fbLibrary->api('https://graph.facebook.com/me/learnthrusong:listen?song=https://www.learnthrusong.co.uk/index.php?option=com_muscol&view=song&id=164','POST');
I cannot get this to work. It is throwing the following errors;
Facebook API Error: An access token is required to request this resource.
Warning: Invalid argument supplied for foreach() in [root]/administrator/components/com_jfbconnect/assets/facebook-api/base_facebook.php on line 858
Warning: http_build_query() [function.http-build-query]: Parameter 1 expected to be Array or Object. Incorrect value given in [root]/administrator/components/com_jfbconnect/assets/facebook-api/base_facebook.php on line 893

I presumed (probably incorrectly), that the API key/tokens would be handled by the call on the api. This is clearly part of the issue.

I wonder, please could you advise on how to achieve this, including, what arguments I need to pass to enable me to process this action for the current logged-in user?

Many thanks in advance!

Gez
The topic has been locked.
Active Subscriptions:

None
12 years 2 weeks ago #21582 by learnthrusong
UPDATE:
Hi Alex, as you mentioned in your PM, it would be great if you could shed any light on the PHP approach to posting however, I've been so close to this today I couldn't see what's been staring me right in the face!

The most OBVIOUS thing I've been missing: I can do all my php procesing, db queries etc but then just post to facebook using the javascript methods - BOOM!!!

Thanks Again!

Gez
The topic has been locked.
Active Subscriptions:

None
12 years 5 days ago #21897 by fb_546164587
Are there any FBConnect tags that we can use to trigger actions?
The topic has been locked.
Active Subscriptions:

None
12 years 5 days ago #21899 by learnthrusong
Hi there...

No, currently not any... It's actually pretty stright forward using the JS API call. Please see above...

My only issue was that I needed to do some extra DB stuff before hand. I've now worked a way around that to allow me to use the JS api as opposed to the PHP route.

Hope this helps!

Gez
The topic has been locked.
Active Subscriptions:

None
12 years 5 days ago #21904 by fb_546164587
Thanks Gez, however I am still a little confused. Would you be so kind and tell me what exactly you included in the PHP and Javascript files?

I have an events website powered by Jomsocial and I want to send an action Attending to the user's Timeline when the user changes his RSVP to attending.

Thank you in advance!
The topic has been locked.
Active Subscriptions:

None
11 years 11 months ago #23087 by fb_546164587
[edit]
The topic has been locked.
Active Subscriptions:

None
11 years 11 months ago #23088 by fb_546164587
I have the following code included in the PHP file:
require_once JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php'; 
$fbLibrary = JFBConnectFacebookLibrary::getInstance(); 
$fbLibrary->api('https://graph.facebook.com/me/eventhread:attend?event=http://demo.eventhread.com/index.php?option=com_community&view=events&task=viewevent&eventid=4703&groupid=1464&Itemid=238','GET');

However, it throws the following error:
Warning: Invalid argument supplied for foreach() in /homepages/45/d391709137/htdocs/eventhread-site/administrator/components/com_jfbconnect/assets/facebook-api/base_facebook.php on line 858 

Warning: http_build_query() [function.http-build-query]: Parameter 1 expected to be Array or Object. Incorrect value given in /homepages/45/d391709137/htdocs/eventhread-site/administrator/components/com_jfbconnect/assets/facebook-api/base_facebook.php on line 893

Any ideas on how to solve this problem?

Cheers
The topic has been locked.
Support Specialist
11 years 11 months ago #23235 by alzander
Tadas/Gez,
Sorry for the delays in getting back to this. We've been doing some testing with Timeline/Open Graph action stuff, and wanted to post a little of what we've found.

First, and most important, are details on how to post an Open Graph action using the JFBConnect api function. Let's assume your using one of the default "read" actions. These are provided by Facebook, so they don't use your app's own unique namespace. Instead, the action call would look like 'news.read'. To submit an action like this saying the user has 'read' the article at a specific URL, you'd call the following:
require_once JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php'; 
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$args = array();
$args['article'] = 'http://site.com/link-to-full-article.html';
$jfbcLibrary->api('me/news.reads', $args);
The important things are that the 'noun' for the action is passed in through that arguments array. The action (verb) is part of the api call to 'yourself', the me/news.reads.

So, Tadas, if you haven't already gotten it already, I believe the call you'd want to make would be:
$args['event'] = 'http://demo.eventhread.com/index.php?option=com_community&view=events&task=viewevent&eventid=4703&groupid=1464&Itemid=238';
$fbLibrary->api('me/eventhread:attend', $args);
The JFBConnect library will take care of the following things:
* Getting the full Graph API URL
* Setting the action to 'POST' (you were trying GET, which is wrong)
* Automatically using the user's Authentication token
* A few other housekeeping things that are necessary

Please note, to post an action, you need:
* The "publish_actions" permissions from the user. You should add that to the Facebook API tab of the Configuration area of JFBConnect, if it's not there already. JFBConnect can request a similar permission, based on your configuration (mainly if you're posting to wall during login), but it's safer to just add that permission to that box, for now.
* The Open Graph tags for the page must be configured correctly. Mainly, the 'type' setting must be right for the action you are trying to use. In my case above, the type is 'article' (configured in the Open Graph area of the App config on Facebook.com). In Tadas' case, I believe it would be 'event'.
* You can add the OG attribute easily by adding {SCOpenGraph type=blah} tag to the page

We're working on a way to make this all very easy to do through tags and other stuff in articles or through the admin interface. Our goal is to make it simple for everyone, but flexible for those who want to go wild with different actions on events and such. It's going to take some time to get it right, but hopefully the above will hold everyone over with actions for the time being.

Your feedback and experience are more than welcome. We'd love to hear what works, what doesn't, and how you'd like to see things improved!

Thanks,
Alex
The topic has been locked.