Hi, I was wondering if anyone could assist me with a problem that I am having.
So I'm trying to automatically post from my blog to my facebook page. I have done the php separately and it works fine, so now I am thinking about what has to be done to get it incorporated into MODx.
The functionality that I am looking for is, on creation of a new article (i.e Blog Post) some event must be triggered by which a snippet or some other piece of code is called, that will trigger the posting to facebook.
All of this will be done on the back end, that is to say, the creation of the new post together with whatever images/links/etc will be done from the manager, and once it's complete, and saved the event should be triggered calling the code that will make the post to facebook.
Any help will be greatly appreciated.
- Ed
-
☆ A M B ☆
- 24,524 Posts
If you are using the Articles package for this, the plugin would work on the onDocFormSave event, and check to make sure it's a new document and that its class_key is Article (or whatever the class_key for Articles is), then run your code.
I would be interested in seeing your code for posting to Facebook and I think many others would be too.
Your plugin would be something like this (connected to OnDocFormSave):
/* Make sure it's a new doc */
if ($mode !== modSystemEvent::MODE_NEW) return;
/* Make sure it's an Article */
if ($resource->get('class_key') !== 'Article') return;
/* your code here */
return '';
Thanks Ed, does that post to the profile, or the timeline?
It depends on the access token, I think if you get and use the access token for your personal profile (as I was doing), the posts go to the timeline of your profile. If you have a business page or a fan page and use either of their access tokens, it should post to the respective page. As I have neither of those I am unable to confirm but you can try it out and see.
Thanks for posting that. You should consider making it an extra.
I'm actually thinking about that. If it's successful I will upload it. Thanks again for the help.