Topic-icon API for Facebook posting?

10 years 7 months ago #36565 by chramb1
I'd like to leverage JFBConnect to have my self-developed components post to Facebook on behalf of the user.

Is there a pointer to documentation on how I can hit any API endpoints in JFBConnect to do this?

For example, I have a little quiz component I developed. When the user completes a quiz, I'd love to post a graphic to their Facebook feed with some text like, "Suzy Creamcheese completed the 'What color should I dye my hair' quiz an dher answer was 'go bald!'"

Rather than re-invent the wheel, I'm hoping that JFBConnect has an API or injection points I can leverage.
The topic has been locked.
Support Specialist
10 years 7 months ago #36573 by alzander
Replied by alzander on topic API for Facebook posting?
Christopher,
There is a simple call you can use to post a message and image to a user's wall. However, you shouldn't use it unless either:
* The user has an option to see what's about to be posted and be able to disable it
* The user has the option to edit the post before being submitted
Without those conditions, it will violate Facebook's App Policies, which is why we removed the "Post on Login" and "Post on Registration" features from the latest release.

What you *should* do is create an Open Graph Action to post that content. Action posts can be made automatically without the user's immediate consent. They will go in the Activity Log of the user, and from there, can show up in the Timeline, news ticker or news feed.. but it's not guaranteed how and where it will show up.

So, let me know what you'd like. The feed post is a few lines and super simple.. and it's up to you if you want to follow/break the rules (though getting too many posts marked as spam is a bad thing too). For Open Graph Actions, we have a pretty robust plugin system. It may take an hour or so to create your first plugin, but it will only be about 50 lines and mostly just modifications to our content plugin. JFBConnect will do the heavy lifting beyond that.

Let me know,
Alex
The topic has been locked.
10 years 7 months ago - 10 years 7 months ago #36578 by chramb1
Replied by chramb1 on topic API for Facebook posting?
I'd like to do the post. In this case, I will have permission - when the user completes the quiz, they get their results, and will be presented with a "Post Your Results To Facebook" button. So they will take an affirmative action to make the post.

I'm looking to do a picture post, if that makes a difference - the picture will be a badge with their quiz results.

Anticipating this, I request stream_publish as an additional permission in the registration flow of JFBConnect :-)
Last edit: 10 years 7 months ago by chramb1.
The topic has been locked.
Support Specialist
10 years 7 months ago #36582 by alzander
Replied by alzander on topic API for Facebook posting?
You'll need to make sure your app is requesting the publish_actions permissions. That will let you post Open Graph Actions as well as news feed posts on behalf of the user. You're asking to do the latter. If you have an Actions created, that permission is likely already being requested. You can also ensure it's requested by adding it to the Configuration -> Facebook area.

Once that's done, here's the code to post:
$message = array();
$message['message'] = "I just took this awesome quiz";
$message['link'] = 'http://domain.com/link-to-quiz'; // or home page, or whatever
$message['picture'] = 'http://domain.com/picture.jpg';
JFBCFactory::provider('facebook')->setFacebookMessage($message);
Test and let me know how it goes!

Alex
The topic has been locked.
10 years 6 months ago #37616 by chramb1
Replied by chramb1 on topic API for Facebook posting?
I've gotten to the point in development of this component to test the above.

Good news and bad news.

Good news: it works perfectly.

Bad news: if only works perfectly if the user is logged in with an associated Facebook account. If the user is not logged in (thus is a "guest" user on my Joomla) it does not work. This, however, has been tested with a browser where the user *is* logged in to Facebook as well as not logged in.

One would expect that if the user were logged in to Facebook already, this should work silently and if they are not, it should present them with an authentication dialog, no?

We're going to have a slew of guest users take quizzes. We'd like to be able to post their results to Facebook because they're going to want that.

I am guessing that this code, above, presumes the user is logged in and uses internal credentials to set up the Facebook API call. I need it to work in non-logged-in situations as well. Is this possible?
The topic has been locked.
Support Specialist
10 years 6 months ago #37627 by alzander
Replied by alzander on topic API for Facebook posting?
The API method I gave you is for automatically posting on the user's behalf to their wall. That's not something that can be done without the user having granted the publish_actions permission for your app, and that's only done after they've logged into your app/website. If you could post to anyone's wall that was merely logged into Facebook when they visited your site.. well, you can imagine the abuse that would happen.

For users that aren't logged in, you could show a "Post to Wall" option where the user can choose to post the message to their wall. This can't be done through the API though as you wouldn't have the authentication token required to do it that way. For showing a feed post popup, you can use the following link:
<a href="javascript:void(0)" onclick="jfbc.social.feedPost('I took a quiz', 'caption for quiz', 'description of quiz', 'http://site.com/link-to-quiz', 'http://site.com/link-to-image-for-quiz.jpg')">I took this quiz</a>
That will bring up a popup with the parameters set above (title, caption, description, url, image) that the user can choose to take to post to their wall.

With that code, you could have 2 options in your code: a) auto-post if the user is logged into your site using Facebook or b) show the link to let any other type of user (guest or joomla-only user) make a post.

I hope that helps give you an idea, but let me know if you have any questions!
Alex
The topic has been locked.
10 years 6 months ago #37640 by chramb1
Replied by chramb1 on topic API for Facebook posting?
So check my logic here.

I test for login after the quiz is done. If the user is logged in, I hit your API for autopost, as I should have permission. I'll need to check the output of the API post for success. If it fails or the user isn't logged in, I, instead, output the link code, above.

That should do it, other than the fact that you eat the output from the API call and don't return it :-) ... can you make the API call return the results? You capture them in $result so you could return that (and also return a result in the case of the exception, which right now you trap and eat).

Knowing if the API call succeeded is required.
The topic has been locked.
Support Specialist
10 years 6 months ago #37645 by alzander
Replied by alzander on topic API for Facebook posting?
Yeah, looks like we're greedy there, for some reason. That code is old and not called by us directly anymore, it's just for our users. We're planning a new 'update stream' type call that would be compatible across any providers that support posting to the user's 'stream', whatever that is (wall, twitter feed, etc). So, until then, feel free to update the function and return what you need.. and hopefully in the next release (or the one after that.. depends on time), we'll have the uniform posting method ability implemented to use and get a better result.

As for your logic of posting, it sounds like you got it. You could, instead of checking if the post was successful, just check if the user is logged in via Facebook (or if they are logged in and the post succeeded, whatever you think would work best). In general though, that's the flow.

Let me know if you have any questions though, as always, and we'll help get you going.

Thanks,
Alex
The topic has been locked.