posts in group feed have unavailable content - facebook

I am an admin of a private group in facebook and I would like to use facebook API to scrap all group posts.
I used graph api explorer to generate an access token with read_stream, friends_group and user_groups permissions.
When I access the group post with https://graph.facebook.com/GROUP_ID/feed?access_token=TOKEN I get a data array with each post but the caption element has the value
"Attachment UnavailableThis attachment may have been removed or the person who shared it may not have permission to share it with you." and all the other fields such as link, message, etc ... are not present.
If I open the facebook group using the browser I can see all posts.
Am I missing something here ?

This issue appears to have been corrected. I can access all the Group content for my private group as long as I have a valid Auth Token.

Below is the code where I fetch the posts of a group in a JSON Object. This JSON object contains a JSON Array of "data".
This further contains a separate JSON array for messages (or status of the post).
GraphRequest.newGraphPathRequest(
accessToken, "/id/posts",
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
try {
graphResponse.getRawResponse();
m=graphResponse.getJSONObject();
JSONArray n=m.getJSONArray("data");
messages=new String[n.length()];
for(int i=0;i<n.length();i++) {
JSONObject a = n.getJSONObject(i);
messages[i]=a.optString("message");
}
list.setAdapter(new ArrayAdapter<String> (fb.this,android.R.layout.simple_list_item_1,messages));
} catch (Exception e) {
Toast.makeText(fb.this, "error is: " + e.toString(), Toast.LENGTH_LONG).show();
}
}
}).executeAsync();

Related

Weird error message for denied fb app item submission

This is not for Facebook api authentication but for item permission management for the app.
I'm currently in the process of resubmitting my application for item approval. One of the items I previously submitted and was rejected was the read_friendlists item. Here's the weird part..
This is the error message that I got from the submission:
it looks like you haven't made any API requests to access content with the read_friendlists permission in the last 30 days
I don't understand what the message means. Im in the process of getting this permission.
You might have to explicitly request those Fields in the request parameter when asking Friend's data.
for example
private void makeMyFriendsRequest(final Session session) {
Request request = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
// If the response is successful
if (session == Session.getActiveSession()) {
for (GraphUser user : users) {
System.out.println(user.getFirstName() + " " + user.getLastName());
System.out.println(users.get(i).getId());
GraphLocation loc = users.get(i).getLocation();
System.out.println(loc != null ? loc.getCity() : "loc not available");
}
}
}
});
// here add fields explicitly
Bundle bundle = request.getParameters();
bundle.putString("fields", "id,first_name,last_name,birthday,location");
request.executeAsync();
I hope this will help.

facebook c# SDK get albums and images

what i am trying to achieve should be simple by theory but hell by implementation, if you think otherwise please help.
so what i am trying to achieve here is that I have my facebook page which I created a developer acount for it, and what i want is to take albums from the page to my website.
I am using the latest stable facebook sdk for .net 6.8.0, and i am assuming that the graph api is on v2.2.
this is the code i am using below to get the access token and access my albums
try
{
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = "---my application number---",
client_secret = "---my application secret---",
grant_type = "client_credentials"
});
var fb2 = new FacebookClient(result.access_token);
dynamic albums = fb2.Get("my application number/albums");
foreach (dynamic albumInfo in albums)
{
try
{
dynamic albumsPhotos = fb2.GetTaskAsync(albumInfo.id + "/photos");
}
catch (Exception Exception)
{
throw Exception;
}
}
}
catch (Exception e)
{
throw e;
}
The data returned in the dynamic albums variables is empty, the thing that confused me more is when i use facebook graph api explorer the call work fine and it return the albums. so what exactly i am missing.
I also read in some threads that you can access your albums without the secret password if they are public but that didn't work for me either i tried it in javascript but no joy.
Thank you in advance.
Since this is your page, it should be pretty easy to retrieve your own photos using Windows PowerShell and http://facebookpsmodule.codeplex.com Get-FBAlbums.

How to mention user/page in post on wall using facebook api?

I've found format
#[id:1:anchor]
where id is user id or page id and anchor is text displayed.
This format is not documented on official facebook dev page, thus working.
What is the status of issue? Are there any alternatives?
There is no way to add tags in text this way via the API. There were loopholes which allowed this to work but they were closed shortly afterwards
i got the solution for this, here the using c# code:
protected void btnPost_Click(object sender, EventArgs e)
{
var client = new FacebookClient("YOUR FB TOKEN HERE");
var parameters = new Dictionary<string, object>
{
{"message", "YOUR STATUS HERE" },
{"tags" , "YOUR FRIENDS FB ID HERE"},
{"place" , "YOUR PLACE ID HERE"}
};
client.Post("me/feed", parameters);
lblPost.ForeColor = System.Drawing.Color.Red;
lblPost.Text = "Status Updated!";

Retrieve Facebook Post Comments Using Graph API

I tried to get Facebook comments using:
http://graph.facebook.com/[post_id]/comments
It results only 2 of 15 comments, and without count info.
{
"data": [
{
"id": "[post_id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T02:36:23+0000"
},
{
"id": "[id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T05:16:56+0000"
}
]
}
Anyone know why only 2 comments?
Also, I want to retrieve comments (default number) or retrieve comments with my limit number, and get its comments count. Any idea? (Please use Graph API).
You need to call it from a secure request https and provide an access_token:
https://graph.facebook.com/19292868552_118464504835613/comments?access_token=XXX
EDIT:
Added the object from the post document. try clicking the comments connection and then remove the access_token and try and see the difference.
In order to get the Like count and the comment count then you need to use a combination of the PostOwnerID and PostID not just the PostID
So for your example it would be:
https://graph.facebook.com/153125724720582_184234384932460/comments
Again, as mentioned in some of the other answers you need to use the https method along with an auth_token
I experienced the same problem with comments. The issue was that I was using an access token for a test user. Because test users don't have access to other FB users information, only the comments from pages were shown.
There is a word JUGAAR in Urdu that means, finding a way out, just to get the job done. So for like purpose I made this JUGAAR, I hope it helps.
$contents = file_get_contents("http://graph.facebook.com/" . $_GET['id'] . "/likes");
if (substr_count($contents, 'name')>0) {
echo substr_count($contents, 'name') . " people like this album";
}
By the way I am also new to this Fb stuff, I am looking for help to post comments. When I try to use graph.api./id/comments?access_token=sdfsfsdf&message="D" it still returns comments for the id instead of posting.
As a sanity check, do you have "read_stream" permission? I can see the full comments with my access token that uses "read_stream". As mentioned by other people, you have to use https and access token as well...
Try to authenticate via App Login (http://developers.facebook.com/docs/authentication) and then to call GraphAPI with access_token prarameter.
You can do something like this to avoid the whole count of comments issues:
Get the object's (a post is considered an object in the Graph API) ID-as I understand from your question, you already have it?
Create a Comments Social Plugin with this ID, and get the code for it.
Embed the code in your site.
This will result in all the comments for this object.
To get the count of comments per object, you can execute an fql query, something like this:
SELECT comments FROM stream WHERE post_id = [yourpostid]
This will return in the comments array under the count parameter the number of counts for this object.
SELECT comments FROM stream WHERE post_id = [yourpostid] shall not work in this case ..
the id which is returned after making a graph call successfully to post on a user's wall (using access_token of an application ) is of the form abcdef_qwerty ( underscore seperated id )
where as the post id which is mapped in the post_id of the comments table is of the form "lmnop" ..
to get the counts of like and comments on this post id of form "abcdef_qwerty" making a graph call withh app generated access token seems to be the only solution ..
something like:
https://graph.facebook.com/100002619172565_117323155031656?access_token=xxxxxxxxxxxxx
After Successfully Login call this method facebookComments()
parameters.putString("fields", "message"); .............// Its Important
AccessToken accessToken = AccessToken.getCurrentAccessToken();
public void facebookComments() {
try {
getFriends(accessToken, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("keshav", "one" + response);
CommonMethod.showAlert("res --> " + response, MainActivity.this);
}
}
);
} catch (Exception e) {
CommonMethod.showAlert("Exception is -> " + e, MainActivity.this);
}
}
public void getFriends(AccessToken token, GraphRequest.Callback callback)
{
// TODO Comments Working but id return only
GraphRequest requestt = new GraphRequest(token, "744511125731315_751199848395776/comments",
null, HttpMethod.GET, callback);
Bundle parameters = new Bundle();
parameters.putString("fields", "id"); // todo in use imp
parameters.putString("fields", "name"); // todo in use imp
parameters.putString("fields", "from"); // todo in use imp
parameters.putString("fields", "message"); // todo in use imp
requestt.setParameters(parameters);
requestt.executeAsync();
}
It results only 2 of 15 comments
Add a limit parameter to the URL:
http://graph.facebook.com/[post_id]/comments?limit=1000&access_token=XXX
This should show all the comments.

Specify privacy when POSTing to Facebook Graph API

I want to automatically post Notes on Facebook and have them be targeted to just a single member of a group. By target I mean only a specific Facebook user should be able to read the note.
Is there a way to do this with the graph API? I see in the old REST API there is a "privacy" parameter on the steam.publish method (see http://developers.facebook.com/docs/reference/rest/stream.publish). Is there an equivalent in the graph API?
Here's the answer.
Just include "privacy" in the Bundle in JSONObject format, including value "SELF", "ALL_FRIENDS" OR "EVERYONE".
This is using android SDK 2.0, and 3.0 is now avaliable, But the way to use graph api is the same, left comment if you reach any problem:).
public String PostWall(String Message,int Level){
/***********************************************************
* level 0 ==>only me
* level 1==>friend only
* level 2==>public
* level >2 ==>error
***********************************************************/
Bundle params = new Bundle();
params.putString("message", Message);
JSONObject privacy = new JSONObject();
try {
switch (Level){
case 0:
privacy.put("value", "SELF");
break;
case 1:
privacy.put("value", "ALL_FRIENDS");
break;
case 2:
privacy.put("value", "EVERYONE");
break;
}
} catch (JSONException e1) {
}
params.putString("privacy", privacy.toString());
//Step 2 Request
String resp= "";
try {
resp = fb.request("me/feed", params, "POST");
} catch (FileNotFoundException e) {
} catch (MalformedURLException e) {
} catch (IOException e) {
}
try{
resp = new JSONObject(resp).getString("id");
if(enableLog){
Log.d(LOGTAG,"*****POSTWALL END*****");
Log.d(LOGTAG,"RETURN "+resp);
}
return resp;
}catch(JSONException e1){
}
}
};
You can use SELF
php facebook api example:
$privacy = array(
'value' => 'SELF' //private
);
$publish = $facebook->post('/me/videos',
array('access_token' => $page_token,
'title'=> $title,
'privacy'=> $privacy,
'source' => $facebook->videoToUpload($fn),
'description' => $desc
));
object containing the value field and optional friends, networks,
allow and deny fields.
The value field may specify one of the following strings: EVERYONE,
ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM .
The friends field must be specified if value is set to CUSTOM and
contain one of the following strings: EVERYONE, NETWORKS_FRIENDS (when
the object can be seen by networks and friends), FRIENDS_OF_FRIENDS,
ALL_FRIENDS, SOME_FRIENDS, SELF, or NO_FRIENDS (when the object can be
seen by a network only).
The networks field may contain a comma-separated list of network IDs
that can see the object, or 1 for all of a user's network.
The allow field must be specified when the friends value is set to
SOME_FRIENDS and must specify a comma-separated list of user IDs and
friend list IDs that 'can' see the post.
The deny field may be specified if the friends field is set to
SOME_FRIENDS and must specify a comma-separated list of user IDs and
friend list IDs that 'cannot' see the post.
Search for privacy on the following link to see all options:
https://developers.facebook.com/docs/graph-api/reference/v2.6/post
Yes, there is:
http://developers.facebook.com/docs/reference/api/post
There's a field called privacy which you can modify.
Hope that helps,
-Roozbeh
http://developers.facebook.com/docs/reference/api/post
does not tell how to specify privacy
in correct way
for varied option CUSTOM, FRIENDS, NETWORK_FRIENDS
If you are posting notes from an app, you can set default activity privacy as shown here:
It could be set when you are authenticating your own application, or in: account settings - > applications.