iPhone facebook integration - iphone

I am using Graph API in my application. I am fetching user's facebook wall feeds using graph API also getting details of particular post i.e (Like count,Comments etc).
but i want to allow user to Like and Comment any post from the application itself.
what is the request format for that?
Please help me or give any pointers.
Regards,
Sanket

You would be well served to check out the Publishing section of the documentation. It provides information such as this.
One example is liking, which is defined as:
Method: /OBJECT_ID/likes
Description: Like the given object (if it has a /likes connection)
Arguments: none
Basically, just initiate a Graph API call to something like:
[facebookObject requestWithGraphPath:#"98423808305/likes" andDelegate:self];
That will "like" a picture from Coca-Cola (ID taken from the documentation).
Edit 1
According to the documentation:
Most write operations require extended permissions for the active user. See the authentication guide for details on how you can request extended permissions from the user during the authentication step.
Are you sure you have enough privileges? Unfortunately the documentation is very unclear as to whether it serves the dual purpose of liking the object and returning the likes already on that object.
Edit 2
I did some more research into what could be causing this and came across this question and answer that indicated that the code I posted above using requestWithGraphPath:: should work. However, it does not due to a bug on Facebook's Bug Tracker.
Unfortunately, it looks like there is no way to "like" an object via the Graph API, which seems very strange to me. Perhaps it is possible with the legacy REST API instead of the Graph API?
Edit 3
Well, it looks like your best bet is the stream.addLike method of the legacy REST API which you can still call using the Facebook iOS SDK. You should be able to use the stream.addLike method to "like" something in the "stream". Unfortunately, it doesn't appear to support photos, videos, etc. Only posts and comments.

Finally i found the solution for LIKE option
We should use following method for like option.
-(void) requestWithGraphPath:(NSString *)graphPath
andParams:(NSMutableDictionary *)params
andHttpMethod:(NSString *)httpMethod
andDelegate:(id <FBRequestDelegate>)delegate
graphPath = /OBJECT_ID/likes
Paramas = dictionary with comment ,for like option use empty dictionary
HttpMethod should be POST
you should get response = true if the LIKE request is successful.

Related

How do I get the Explore and Stream section from the SoundCloud API

I can't seem to find the section in their api reference. I tried it as a searchquery but it doesn't seem to work. api.soundcloud.com/stream or /explore return a 404, so that doesn't work either
Thats actually not a part of the public API.
But its quite easy to grab your call from the dev console.
Thats an example call from my user:
https://api-v2.soundcloud.com/stream?user_id=e87647259112403eaa239b6e2c510e46&sc_a_id=e87647259112403eaa239b6e2c510e46&user_urn=soundcloud%3Ausers%3A1672444&promoted_playlist=true&limit=10&offset=0&linked_partitioning=1&client_id=02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea&app_version=a089efd
To make that call work, you need to modify the headers.
These answers may help you:
Retrieving the "recommended" playlist via API call?
soundcloud: Is api-v2 allowed to be used and is there documentation on it?
How to get "all" tracks related to an artist with Souncloud API
Using these endpoints does not go inline with SoundClouds TOS.

Empty response to API call to Facebook Graph

I have been hammering away at this problem for the last day. I really hope someone can help me out. I would be very grateful.
What I am trying to do is fetch event data from a Facebook Page. I looked over the documentation, which says this about reading Pages data:
Reading
A Facebook page
Permissions
For pages that are published, you need:
An app or user access token to view fields from fully public pages.
So what I did was I obtained an app access token via:
GET https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID
&client_secret=YOUR_APP_SECRET
&grant_type=client_credentials
which then returned
access_token=MY_APP_ID|MY_APP_ACCESS_TOKEN
After this I followed the documentation and made the following call
https://graph.facebook.com/v2.4/129511477069092/events?fields=id,cover,name,venue,description&access_token=MY_APP_ID|MY_APP_ACCESS_TOKEN
This returned:
{
"data": [
]
}
So after some fiddling around I was able to make the call by switching to version V2.2 and by creating an access key with Facebook API Graph explorer tool(no permissions granted).
GET https://graph.facebook.com/v2.2/129511477069092/events?
fields=id,cover,name,venue,description&
access_token=ACCESS_TOKEN_FROM_FACEBOOK_API_EXPLORER_TOOL
The page I am trying to retrieve data from is public and so are the events, so I can't figure out what is going on. I know I am super close since I am able to retrieve the data with the token provided by the Facebook API Graph Explorer Tool. The thing with using this token is that it only last a few hours and I need something that is going to last longer such as an app access token. I have done some research on Stackoverflow and found similar questions, but none of them solve my problem. Any help will be appreciated to the max! Thanks.
Looks like a bug of v2.4 to me. It works with v2.3 if you remove the deprecated venue field:
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=129511477069092%2Fevents%3Ffields%3Did%2Ccover%2Cname%2Cdescription&version=v2.3
If the version is changed to v2.4, it returns an empty result.
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=129511477069092%2Fevents%3Ffields%3Did%2Ccover%2Cname%2Cdescription&version=v2.4
There's no documentation about this in the changelog at
https://developers.facebook.com/docs/apps/changelog#v2_4
so I guess it's a bug. There's already a bug report at
https://developers.facebook.com/bugs/443054055873667/
with status assigned. If you have an app that supports v2.3, I'd suggest you prefix your request like this:
GET /v2.3/129511477069092/events?fields=id,cover,name,description

Facebook graph api - Unsupported get request

I'm creating a custom module in Drupal, that for part of its functionality must fetch posts from a business page. So for simplicity, I'm using fbapp module as a dependency (drupal.org/project/fbapp), so that I can use it's authentication and request functions (fbapp_app_authenticate() and fbapp_graph_request()) without having to worry about the constant facebook graph updates making my own code obsolete.
I've created a facebook app, so authentication should be app token, using appid and app secret. This seems fine and I'm getting back access_token. However, when I try to read posts from a publicly available page (the clients), I get the response:
"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api"
Here's the queries and responses my code produces:
graph.facebook.com/oauth/access_token?client_id=<redacted>&client_secret=<redacted>&grant_type=client_credentials
array(1) {
["access_token"]=>
string(43) "<redacted>|<redacted>"
}
graph.facebook.com/<page_id>/posts?access_token=<redacted>|<redacted>"
string(183) "{"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}}"
Can anyone verify a correct way to query a Facebook page programmatically, perhaps there's a setting in the page I'm querying that I need to set (although I can't find anything)?
If page restrictions apply, the page's feed can only be retrieved with an user access token as far as I know (because FB needs to evaluate the visibility criteria, and setting your app to the same restrictions doesn't help here):
See
https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed#readperms
It looks like everything you have done is correct. The response you got can be (i am not sure) because you got your clients pageid wrong.

How to get facebook share, like, comment count for a url with graph api only (in a non-deprecated way)

The problem is that after v2.1 of graph api fql will be deprecated.
Can someone tell me how to get separate likes, share count for given url using only graph api? I was looking for some documentation, but there isn't any, i can get only total "shares" which is likes + shares + comments.
Yes i know there is immortal http://api.facebook.com/restserver.php?method=links.getStats&urls, but what if facebook shuts it down at last?
The REST API (with calls like http://api.facebook.com/restserver.php?method=links.getStats&urls) was announced as deprecated with the introduction of the Graph API v2.1: https://developers.facebook.com/docs/apps/changelog#v2_1_deprecations but also already in 2011: https://developers.facebook.com/blog/post/616/
So, from my understanding, this will yield in the inoperability of this feature at two years after the introduction of v2.1 on 7th August 2016:
https://developers.facebook.com/docs/apps/versions#howlong
The closest you can get to the "old" REST of FQL API call results with the Graph API is this afaik:
https://developers.facebook.com/docs/graph-api/reference/v2.3/url/
but it omits the like_count metric (don't ask me why...).
My personal opinion is that you should continue to use the FQL calls to the link_stat (https://developers.facebook.com/docs/reference/fql/link_stat/) table, because this will be available for nearly the next 2 years. This is only possible if you have a v2.0 app. Maybe there'll be some additional endpoints for the Graph API until then.
I suggest using a tool like SharedCount, it offers a lot more platforms too. Here is how they get the data: http://www.sharedcount.com/documentation.php (Scroll down to "Sources")
So for Facebook it would be like this:
https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
You get a JSON object like this one:
..."share_count":66,"like_count":15,"comment_count":1,"total_count":82...
Edit: This is deprecated now, but there is another possibility, explained in this thread: Get FB likes, shares and comments for a URL using PHP - with no limit
You can use facebook graph api like https://graph.facebook.com/?ids=http://mycodingtricks.com and it will return a json code like
{
"http://mycodingtricks.com":{
"id":"http://mycodingtricks.com",
"shares":1
}
}
I have developed my own php script on which you can all social count using that api.
http://mycodingtricks.com/share/social.php?url=YOUR-URL-HERE and it will return data like:
{
"facebook":[
{
"share_count":1,
"like_count":0,
"comment_count":0,
"total_count":1,
"click_count":0,
"comments_fbid":567687199998199,
"commentsbox_count":0
}
],
"googleplus":10,
"twitter":3,
"buffer":0,
"pinterest":0,
"stumblupon":1,
"reddit":"<html><body><h1>403 Forbidden<\/h1>\nRequest forbidden by administrative rules.\n<\/body><\/html>\n",
"linkedin":0
}
But if you wants to use on your own Here is a complete article about how to count facebook share,like and all.
http://mycodingtricks.com/php/2-ways-to-count-facebook-likes-shares-and-comments-using-php/
actually the correct way for getting the like number is this:
http://graph.facebook.com/v2.5/?id=YOUR_URL&fields=og_object{engagement}
the brackets after the og_object is the second level of og_object.
see documentation here:
https://developers.facebook.com/docs/graph-api/reference/url
you might need to encode the url and brackets so it will look something like:
https://graph.facebook.com/v2.5/?id=ENCODED_URL&fields=og_object%7Bengagement%7D&id=http%3A%2F%2Fwww.cnn.com
see a working example in
graph explorer (hit the submit button)
All answers are wrong or incomplete since latest shut down of API 2.1!
I am the author of the social media plugin MashShare and i recently had to do exact observations for this issue as it seriously affected the share count of our plugin.
Verified data by observations:
https://graph.facebook.com/v2.7/?id=https://www.mashshare.net contains shares and likes.
As far as i found out the only way to get a number near the real share count of a post is to get first the likes of a url. Than take this number and subtract it from the total number of shares and likes.
To get the like count you need to take the object id of the url and create another API request:
https://graph.facebook.com/v2.7/14206851986099/likes?summary=true
If you know how to merge both requests into one please let me know.
As of August 19th 2016 facebook completely shutdown their rest API.
The only alternative is to use the graph API as suggested above.

Yammer REST API - Documented Parameter not working

The API documented here - http://developer.yammer.com/restapi/#rest-users clearly states:
"4) Alias to /api/v1/users/current user’s id.format. Supports include_followed_users, include_followed_tags, and include_group_memberships parameters.
GET https://www.yammer.com/api/v1/users/by_email.json?email=user#domain.com`
Yet, when we try this, it does not return any followed user information at all! The request we're using is like so:
https://www.yammer.com/api/v1/users/by_email.json?email=me#company.com&include_followed_users=true
However, this request DOES return followed users, but only for the current user:
https://www.yammer.com/api/v1/users/current.json?include_followed_users=true
Am I missing something completely obvious and being stupid or is there a real issue here? If this was taken out for whatever reason, then you'd have thought that the API documentation would have been updated.
The Yammer Team did eventually get back to me on this. Their response below:
(I've removed https://www.yammer.com from URLs because I don't have enough rep' to post more links)
Hey Jason Dunbar looks like the documentation here is wrong.
I looked in to this and had some conversations with a few engineers this week and have the following (albeit more arduous workaround):
1) Call get user by email endpoint and retrieve the id attribute from here: /api/v1/users/by_email.json?email=user…
2) To grab following users, take that id and:
GET /api/v1/users/following/[:id].json
3) To grab group memberships for that user you'll need to impersonate him/her (verified admin only) and
GET /api/v1/users/current.json
We'll get the documentation updated ASAP with this. Also happy to keep the conversation going to help if needed.
Make sure you are setting the email parameter to the user's email that they are registered with.
E.G. if your company has multiple domains but the Yammer network is under bigco.com and the user is registered with an email under bigcosubsidiary.com you'll need to make a request to the API with user#bigcosubsidiary.com.
-as mentioned - it looks like its only for current.json - you can check it here http://yammer-dev.herokuapp.com/endpoints/4 - hope it helps.
Rich