Last active
August 8, 2016 09:47
-
-
Save adib2149/15840abab277eec18903223d37f2e66d to your computer and use it in GitHub Desktop.
just a basic workflow on how to post on Facebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* needs permission: user_photos, publish_actions | |
* | |
* PSEUDOCODE: | |
* if (hasPhoto) { | |
* albumId = getAlbumId(); | |
* if (albumId == null) { | |
* albumId = createAndGetAlbumId(); | |
* } | |
* photoId(s) = addPhotoToAlbumAndGetId(albumId); | |
* postCheckin(text, link, friends, locationId, photoId(s)); | |
* } else { | |
* postCheckin(text, link, friends, locationId); | |
* } | |
*/ | |
public int getAlbumId() { | |
// graph api request: GET "me/albums", | |
GraphRequest request = GraphRequest.newGraphPathRequest( | |
accessToken, | |
"/me/albums", | |
new GraphRequest.Callback() { | |
@Override | |
public void onCompleted(GraphResponse response) { | |
// Insert your code here and get id | |
} | |
}); | |
request.executeAsync(); | |
} | |
public int createAndGetAlbumId() { | |
// graph api request: GET "me/albums" | |
GraphRequest request = GraphRequest.newPostRequest( | |
accessToken, | |
"/me/albums", | |
new JSONObject("{\"name\":\"Harriken Photos\",\"message\":\"A collection of all photos posted via Harriken\"}"), | |
new GraphRequest.Callback() { | |
@Override | |
public void onCompleted(GraphResponse response) { | |
// Insert your code here and get the retrieved id | |
} | |
}); | |
request.executeAsync(); | |
} | |
public int addPhotoToAlbumAndGetId() { | |
// graph api request: POST "me/albums" url=http://i.imgur.com/LIrznUW.jpg | message=the same text as checkin text | no_story=true | |
GraphRequest request = GraphRequest.newPostRequest( | |
accessToken, | |
"/297664400593303/photos", | |
new JSONObject("{\"url\":\"http://i.imgur.com/LIrznUW.jpg\",\"message\":\"the same text as checkin text\",\"no_story\":\"true\"}"), | |
new GraphRequest.Callback() { | |
@Override | |
public void onCompleted(GraphResponse response) { | |
// Insert your code here | |
} | |
}); | |
request.executeAsync(); | |
} | |
public void postCheckin() { | |
// graph api request: POST "me/feed" message=Just%20checking | place=1234 | tags=1471580256%2C1471580256 | link=www.facebook.com | object_attachment=297669540592789 | |
GraphRequest request = GraphRequest.newPostRequest( | |
accessToken, | |
"/me/feed", | |
new JSONObject("{\"message\":\"Just checking\",\"place\":\"1234\",\"tags\":\"1471580256,1471580256\",\"link\":\"www.facebook.com\",\"object_attachment\":\"297669540592789\"}"), | |
new GraphRequest.Callback() { | |
@Override | |
public void onCompleted(GraphResponse response) { | |
// Insert your code here | |
} | |
}); | |
request.executeAsync(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment