Firstly, we talk about the tasks and tools available on Facebook developers.
Now, login to your FB account, go to "Manage Apps"
Choose "Edit App" or "Create New App".
Here are the basic settings of the App:
Then, choose "Use Graph API Explorer".
Enter the POST action path: "me/victory-test-now:gin"
victory-test-now is the namespace, gin is the Action. You may have to add the Action in the "Open Graph" section beforehand.
The food url is from "Open Graph->Types":
After clicking submit button in the Graph API Explorer, go to the Activity Log of the user. You can see the Action in the Activity Log.
You can add a place field to the POST Action.
The place id can be obtained using the following method.
Click on the profile picture, right click, choose "Copy link address"
For example, the link address is below.
https://www.facebook.com/photo.php?fbid=10150753663333147&set=a.438257763146.238406.145768288146&type=1&source=11
The place id is "145768288146".
The Action can be seen in the Activity Log again.
On Android
Secondly, we highlight how the Android App is able to access the data in Facebook through the Facebook App.
Preparation steps:
- Download the Facebook SDK for Android
- Import the SDK into Eclipse
- Compile and build it
After that, you can start to create an Android App in Eclipse. The good tutorial from FB is listed below:
https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/
After you have created the Android App, we go back to the App Dashboard on Facebook Developers, and register the Android package and activity name in the "Native Android App" settings. As an example, the detail info is shown below.
To get the Key Hash, add the code to the OnCreate() method of the MainActivity class.
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.hellofacebook",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Publish to Facebook FeedIn the Facebook tutorial below,
https://developers.facebook.com/docs/android/scrumptious/publish-open-graph-story/
it talks about publishing to Open Graph story.
You could modify the code to make it publish to Facebook Feed. Sounds interesting, isn't it? The essential changes are:
1) populate the Bundle with the description, link, name, caption
2) change the post action path to "me/feed"
The obvious changes are not difficult. However, you may have to retrieve the user info from List<GraphUser>.
public String announceString;
...
private List<GraphUser> selectedUsers;
...
for (GraphUser user : selectedUsers) {
announceString += user.getName();
}
The changes to AsyncTask:
AsyncTask<Void, Void, Response> task =
new AsyncTask<Void, Void, Response>() {
@Override
protected Response doInBackground(Void... voids) {
// Create an eat action
EatAction eatAction =
GraphObject.Factory.create(EatAction.class);
// Populate the action with the POST parameters:
// the meal, friends, and place info
for (BaseListElement element : listElements) {
element.populateOGAction(eatAction);
}
// Set up a request with the active session, set up
// an HTTP POST to the eat action endpoint
// Request request = new Request(Session.getActiveSession(),
// POST_ACTION_PATH, null, HttpMethod.POST);
Bundle postParams = new Bundle();
postParams.putString("name", "Gin food");
postParams.putString("caption", "Gin food");
postParams.putString("description", announceString);
postParams.putString("link", announceUrl);
Request request = new Request(Session.getActiveSession(),
"me/feed", postParams, HttpMethod.POST);
// Add the post parameter, the eat action
request.setGraphObject(eatAction);
// Execute the request synchronously in the background
// and return the response.
return request.executeAndWait();
}
@Override
protected void onPostExecute(Response response) {
// When the task completes, process
// the response on the main thread
onPostActionResponse(response);
}
};