I have read this "Facebook comment-count always showing 0" but it isn't my case.
I use graph API for android to count number of comments on a url link. Just look a simple example:
1 - Use graph explorer: Press this. You will see the result is "comment_count": 47 at this time, and a line "id": "https://developers.facebook.com/docs/plugins/comments/" that content the link we count.
2 - But when I use android facebook graph to query the link like this:
String linkt = "https://developers.facebook.com/docs/plugins/comments/";
String graphLink = "/v2.2/?format=json&fields=share{comment_count}&id=" + linkt;
I got the result {"id":"https:\/\/developers.facebook.com\/docs\/plugins\/comments\/?format=json","share":{"comment_count":0}}
Do you see the "?format=json" was automatically added to my url. So the result is always 0. Because it a wrong url.
Thank you for all help.
I added "&" after my link to separate with "?format=j", then it worked.
Related
I am having trouble while trying to post a message on the current end-user Facebook wall with my Android Application.
So far :
The user is logged in with all the required permissions, especially
the publish_actions permission ;
I am using the last version of Facebook SDK 3.x & Graph API v2 as of May 2014
Post to wall works now as of EDIT 2, but there are issues with
privacy settings : post cannot be seen by anyone not even the
recipient who is tagged in the post ! See EDIT 2 for more details
Here is the documentation for posting a message on the user wall :
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed (go to Publishing)
Regarding the message that needs to be posted on the user' wall, I need to tag some friends that were previously selected by the user.
But to use the tag field I need to use the place field.
The documentation says :
Name: tags
Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a place.
Type: csv[string]
Name: place
Page ID of a location associated with this post.
Type: string
What is location page ID ? How do I get it ?
Oddly enough, in my specefic case, I am offering the possibilty to the user to share is upcoming travel on Facebook.
More oddly enough, this travel is defined by dates and a destination (name of destination + latitude & longitude). The user has the possibility to also share this travel to his friends that are located in his travel's destination hence the need to tag his friends to the wall post.
[EDIT 1]
After looking into #Tobi solutions, I managed to post a message on the end-user wall (in my case me, since I am the developper).
So far : the message is correctly displayed with a friend tagged (a dummy account I use for tests purpouses) and there is also the place : Paris, France.
Using the following search query (thanks #Tobi) search?q=Paris,France&type=place I can get the ID of Paris, France.
Since I did not code the part to retrieve the Place ID it put it manually in the code for the sake of testing the feature first.
[END OF EDIT 1]
[EDIT 2]
I noticed I forgot to add the part with the privacy values to my args Bundle. But it did not change a damn thing : my post is only visible to me alone.
Going to my Facebook wall, here is what I get :
Hovering the public parameters of the posts (a padlock icon) says "All tagged persons".
Clicking on the icon shows the list of settings with only "Only me" selected.
Why "only me" even though I specifically said me + my dummy account in the request parameters ?
Even weirder : changing the property of the publication parameters to "customized" with my dummy account does not change a damn thing as well. Just why ? Facebook is really getting on my nerve...
For the rest, the message content is correctly displayed and the related place is the good one. At least a got that correctly. But still, I just don't get the rest ...
[END OF EDIT 2]
So here is the updated code :
if (this.session != null && this.session.isOpened()) {
final Bundle args = new Bundle();
if (this.selectedContacts.isEmpty() == false) {
args.putString("message", message);
args.putString("place", "170558129707208"); //manually added Paris, France ID
String tags = "";
//here I made some modifications regarding the tags so that is built correctly
for (int it = 0; it < this.selectedContacts.size(); it++) {
final String name = this.selectedContacts.get(it).toString();
final String friendID = String.valueOf(getIdFromName(name)); // returns an int
if (it == this.selectedContacts.size())
tags += friendID;
else
tags += friendID + ",";
}
// Forgot to add privacy values to bundle !
final JSONObject privacyValues = new JSONObject(); //not android JSON, but JSON-Simple lib
privacyValues.put("value", "CUSTOM");
String allow = this.currentUser.getId() + "," + tags;
privacyValues.put("allow", allow); // to limit the visibility of this post
args.putString("privacy", privacyValues.toJSONString()); //forgot that one...
final Request shareTravelRequest = new Request(this.session, this.currentUser.getID() + "/feed",
args, HttpMethod.POST, new Request.Callback() {
public final void onCompleted(final Response response) {
//TODO
}
}
);
final Response response = shareTravelRequest.executeAndWait();
if (response.getError() == null) // in this case, no error occurred
return true;
else {
this.lastErrorMessage = response.getError().getErrorMessage();
Log.e("Something went wrong while posting Facebook message", this.lastErrorMessage);
Log.e("Error type is", response.getError().getErrorType());
Log.e("Error code is", String.valueOf(response.getError().getErrorCode()));
return false;
}
}
}
Unfortunately I must have mistaken somewhere because although the post does appear on my Facebook wall with my dummy account tagged and with the correct link to the place, my dummy account cannot see the post.
I tried creating manually the same post on my Facebook wall by using the following settings :
First I supplied a message
Second I supplied a place
Third I tagged my dummy account
Four I choose who can see this post : me and my dummy account
And finally, I post the message.
In this case, my dummy account sees the post both on its wall and on my wall.
So I would like to know what parameters I must get wrong because there is not much parameters and I just don't see why.
Thanks !
You can either use the Search and use the type place (https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#search), or, if you have positioning date, use an FQL query on the place table (https://developers.facebook.com/docs/reference/fql/place/) as described here: Facebook places: order results by distance
Use two test accounts made via Facebook Developer App settings and not a dummy account that breaks TOS. Since you request publish_actions you probably didn't submit the app for review. Unless your dummy account is a developer/tester in roles as well (which is breaking the TOS again) then your dummy account will not be able to see the post.
Only developers and testers of an unpublished application can see posts made by that application.
I'm following the documentation of google plus list and I am using this code:
Plus.Activities.List listActivities = plus.activities().list("me", "public");
listActivities.setMaxResults(5L);
// Execute the request for the first page
ActivityFeed activityFeed = listActivities.execute();
// Unwrap the request and extract the pieces we want
List<Activity> activities = activityFeed.getItems();
// Loop through until we arrive at an empty page
while (activities != null) {
for (Activity activity : activities) {
System.out.println("ID " + activity.getId() + " Content: " +
activity.getObject().getContent());
}
// We will know we are on the last page when the next page token is null.
// If this is the case, break.
if (activityFeed.getNextPageToken() == null) {
break;
}
// Prepare to request the next page of activities
listActivities.setPageToken(activityFeed.getNextPageToken());
// Execute and process the next page request
activityFeed = listActivities.execute();
activities = activityFeed.getItems();
This does not work because I have to create a client object. I tried more example but I do not understand how to do. Now:
How do I create a client object?
Where do I insert this client object?
I've seen a lot of answers but none work. You can Help me.
The comment that proceeded that code sample asked you to take a look at the Google+ Java quickstart, see the source file in question for how to set up your credentials and Plus client. You'll also need to authorize your request, that sample project shows how to use Google+ Sign-In to authorize the user to get an access token. You must have an authorized user to search with "me".
This sample is Java code using the Google Java API client library, the Android SDK doesn't include the client library by default, so you'd need to import that into your project.
I think you should take a look at this project : google API calendar
It works exactly like that with the G+ API.
I'm working off Livecode v5.5.4 on the Android platform... I've been able to successfully publish apps, however, can not figure out how to install inneractive ads... As LC has partnered with inneractive they provide direction which suggests its as easy as...
mobileAdRegister "YOUR-AD-KEY" //I've replaced with my APP ID from inneractive
local tDetails
put "30" into tDetails["refresh"] // The advert refresh interval in seconds
put 25 into tDetails["age"] // The age of the target audience
put "male" into tDetails["gender"] // The expected gender of the target audience
mobileAdCreate "myAd1", "banner", (0,0), tDetails
however, nothing seems to work... any LC ppl out there with advice??... thanks
If there's no error reported from Mark's suggestion you might want to ensure it's visible with:
mobileAddSetVisible "myAd1",true
Failing that could you post the result of the mobileAds function and let us know if the adLoaded or adLoadFailed message is being sent to the object that executed mobileAdCreate?
You need to check the value of the result:
mobileAdCreate "myAd1","banner",(0,0),tDetails
put the result into rslt
if rslt is not empty then
beep
answer error rslt
end if
Kind regards,
Mark
I have a method in my app that allows the user to "like" a post in his/her news feed. It's done with a simple graph request using HttpMethod.POST. But when I try to do an "unlike" action using HttpMethod.DELETE, I get an error callback:
02-08 00:35:57.298: I/Detail(2628): {Response: responseCode: 403, graphObject: null, error:
{HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200)
Feed story publishing to other users is disabled for this application}, isFromCache:false}
Now I assume this has something to do with the latest attempt to make all apps that integrate with Facebook use all Facebook looking dialogs and styles, but I could be wrong. Here's the roadmap post that has me suspicious:
Removing ability to post to friends walls via Graph API We will
remove the ability to post to a user's friends' walls via the Graph
API. Specifically, posts against [user_id]/feed where [user_id] is
different from the session user, or stream.publish calls where the
target_id user is different from the session user, will fail. If you
want to allow people to post to their friends' timelines, invoke the
feed dialog. Stories that include friends via user mentions tagging or
action tagging will show up on the friend’s timeline (assuming the
friend approves the tag). For more info, see this blog post.
Any ideas on what I could be doing wrong, or is Facebook just ruining me? Thanks!
EDIT: Here's the code I'm using to run the request.
Request likeRequest = new Request(Utility.fbSession, null, null, null, new Request.Callback() {
#Override
public void onCompleted(Response response) {
String responseString = response.toString();
Log.i("Detail", responseString);
updateDetail();
}
});
HttpMethod nextLikeCall = HttpMethod.DELETE;
likeRequest.setHttpMethod(nextLikeCall);
likeRequest.setGraphPath(itemId+"/likes");
likeRequest.executeAsync();
When you grab the post id from the graph data, it should be in a format like: XXXXX_YYYYY. The XXXXX is simply the users id and YYYYY is the actual post id. What you need to do is extract and use just the YYYYY portion of the post id that graph gives you. so instead of graph.facebook.com/XXXXX_YYYYY/likes.... you want to send graph.facebook.com/YYYYY/likes. This will work with both liking and unliking, you can test in graph explorer first before hacking together a substring extraction method.
Not sure how to extract a section of a string on Android, but I know in Objective-C/iOS, it can be done like this (code not tested, for reference/idea) :
SString *actualPostIdStr; //The String we will put the actual postId in
NSString *oldIdStr = //<the string in format XXXXX_YYYYY>
NSInteger charCount = [oldIdStr length]; //get the length of the original XXXXX_YYYYY string
NSRange fRangeCount = [oldIdStr rangeOfString:#"_"]; //get count of characters to remove (XXXXXX)
if (fRangeCount.location != NSNotFound){
NSInteger startingPos = fRangeCount.location + 1; //get the starting character position of the actual postId
actualPostIdStr = [[oldIdStr substringWithRange:NSMakeRange(startingPos, charCount - startingPos)] copy];
}
Hope this helps.
EDIT:
Ok, so I have been playing around with likes all day... It seems that this method sometimes doesn't work, but it all depends on the type of graph object which you are attempting to like/unlike. For example... plain status posts, this method works perfectly. However, I ran into a problem when trying to like a photo with a message/story post object. It turns out, in the graph data for this type of post object with photo, there is an additional paramter called "object_id", in addition to the plain "id" that is in status post graph data. in this case, with the photo and story post, you need to pass the "object_id", unaltered for successful unliking.
This mess seems like either a bug on FB's end, or they are making changes and disallowing likes/unlikes from graph api & just forgot/haven't to told us yet :) hopefully the former. In the mean time, you're just going to have to use my above answer, but just make sure you test with as many different types of post objects you can find, and use if conditions when a different id (portion of "id"... "object_id"... etc) is required.
Sometimes Daniel McCarthy's method don't work. In this case we need get Graph API request XXX_YYYY, find field object_id and unlike this object_id fid.
I'm using : graph.facebook.com/me/feed?access_token=... to get my wall in json format, however, I can't get all the wall. I can get almost all.
I can get the posts where I'am tagged with #my_name..
I can't get the posts where I'am invoqued by "Who are you with?" option..
however, in the wall web application y can see both messages. but using graph api not.
The documentaion says: "Profile feed (Wall): graph.facebook.com/me/feed?access_token=." ..
I thinks the Wall == graph.facebook.com/me/feed?access_token... but apparently I'm wrong :( ..
Thanks in advance ..
Edit.. more information:
Image 1: We can see posts 1,2,3 and 4 (in red) in the wall ..
Image 2: We can see that the posts 2 and 4 had disappeared of json result.
both, post 2 and 4 are using "Who are you with?" "With hall9000"..
Image 1: http://i.stack.imgur.com/y1mFp.png
Image 2: http://i.stack.imgur.com/9kIKG.png