Recently, I heard that, with the Facebook Open Graph API, it is possible to post to a user’s newsfeed if they have liked a page.
I have been trying my best to follow along with the example, and have created a dummy page.
As far as I understand it, it is necessary to do the following:
- Create the necessary Open Graph tags, including the one for your Facebook app
- I’ve tested it using the Open Graph Debugger
- Add a like button to the page
- ‘Like’ the page
-
Obtain an access token (to post the message)
curl -F grant_type=client_credentials -F client_id=MY_APP_ID -F client_secret=MY_APP_SECRET -F redirect_uri=https://graph.facebook.com/oauth/access_token https://graph.facebook.com/oauth/access_token -
Post to the feed
curl -F 'access_token=ACCESS_TOKEN_FROM_STEP_4' -F 'message=Hello Likers' -F 'id=http://dl.dropbox.com/u/3618086/test.html' https://graph.facebook.com/feed
It’s at this point that the message should be sent to anyone who liked the page. Instead, I get the following error:
{
"error": {
"message": "(#100) http:\/\/dl.dropbox.com\/u\/3618086\/test.html does not resolve to a valid user ID",
"type": "OAuthException",
"code":100
}
}
It’s at this point that I’m confused. I’ve read through these related questions:
- How do I publish to the group of people who liked a webpage or object?
- How do you programmatically publish to the Facebook feed associated with a ‘liked’ page?
- Facebook Exception #100 : Does not resolve to a valid user ID
- How to programmatically publish to a facebook feed for a liked webpage?
- Unable to publish to facebook feed
And have tried their suggestions, but nothing has been successful. What step am I missing?
I can provide further details; I just didn’t want the question to get too long.
Alright, I figured out my problem. I’m including my solution below for the benefit of others.
The steps I’ve listed above are indeed correct, but there are a few things that warrant further explanation to avoid the pitfalls that I fell into.
Posting to people who have liked an item on Facebook
Step 1: Create a Facebook App
http://dropbox.comdropbox.comwhich will allow Facebook to use*.dropbox.com. I also could have donedl.dropbox.comspecifically.Step 2: Create the dummy page
It is very important that you create a dummy page. I found that most of my problems were caused by setting up the initial page wrong. If you create a dummy page, you can experiment (or at least create another dummy page) until everything is working.
Make sure that your page is correct, especially the open graph tags. What does correct look like? You can check out my dummy page, but I’ve included the
<HEAD>below:fb:app_id(which should be your Facebook application id), andog:type. There are multipletypes, and certain ones don’t have publish permissions. For more information, visit the Open Graph API documentation. I initially liked my page when it was an article, which caused many of the problems that I had.Add the like button to the page, along with the Facebook SDK.
Step 3: Like the page
The most straightforward part of the entire process. Visit your dummy page, and press the Like button.
Step 4: Send a message
Assuming that you’ve done the previous steps correctly, the last bit should also be straightforward. I use
curlin my example, but you should be able to get it using any sort of POST request.Obtain an access token.
Obtain the id of your product page.
Post a message to all people who liked your product page.
Step 5: Success!
At this point, hopefully everything has gone well. As the user who liked the page, check out their news feed. You should see a post with the title, image, and description that were on your page. Hooray.
…And that’s how I solved it. Hopefully this will be valuable to other people. I would be glad to elaborate if I have missed any details.