facebook Graph api 2.2 issue - objective-c

How can i get the list of all friends using the graph api 2.2 and also i want to post the text on the friends wall. in iOS application
I tried:
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id<FBGraphUser> result,
NSError *error
) {
/* handle the result */
dicResult =(NSDictionary *) result;
NSLog(#"%#", dicResult);
[self.tblFriendListGroup reloadData];
}];

You can´t get ALL friends anymore, only those who authorized your App too.
You can´t post on the wall of friends. That possibility was removed many years ago because it would always be spam.
Check out the changelog: https://developers.facebook.com/docs/apps/changelog?locale=en_GB

Related

Not getting the email from twitter using Fabric Twitter SDK

This seems to be age old question with no specific answers or solutions for it. I had my application whitelisted from twitter. Done all the things. Checked the request email from user box and used the following code
[[Twitter sharedInstance] startWithConsumerKey:#"FabricKey" consumerSecret:#"FabricSecretKey"];
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
But still it is returning null. Why is this?? I even created the application in twitter developer portal. Please help me. Is twitter trying to be more over secure?? It is just pissing me out......

Check if Authenticated User Likes A Certain Page (Using SLRequest)?

I've been looking through the open grpah reference docs, and can't seem to find a good example related to SLRequest regarding users and whether they like a certain page or not. I don't want to iterate through their entire list of likes.
I was looking at https://developers.facebook.com/docs/graph-api/reference/user/likes/ but I'm not sure how to work with it and SLRequest, I've done the following but I'm receiving the following response:
Received Response: {"error":{"message":"An active access token must be used to query
information about the current
user.","type":"OAuthException","code":2500}}
Thing is all of this code only runs if the suer has previously authenticated and granted permission, and so it must have found an account, yet I still get this respond. Could it be that I'm not requesting a specific permission? I've requested, "email, public_actions, user_likes and public_stream".
BTW I do have another view controller where I ask for these permissions (except user_likes), and everything works in that one. Is there anything that I'm missing here? Thanks!
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/likes/{MYPAGEID}"];
[SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:feedURL parameters:nil];
[updateFeedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData ) {
NSLog(#"Received Response: %#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSLog(#"Successful Connection");
} else {
}
} else {
NSLog(#"No response.");
}
}];
The error that you are getting is received when you try to make calls like /me but no user is currently logged-in to your app or the user has already logged-out of the app.
I'm not sure of your complete flow of the app but you can try this to validate your access token and call- you have the access token right? so, with your current API call just add an extra parameter access_token with its value.

How to get user_likes from Facebook SDK

Im trying to get the user's likes from Facebook, I've been looking for a while for an example and I didn't find it.
With the code I have I get the user's profile information, but no likes. I was wondering if I was doing something wrong and then I looked at Facebook Developers and I found this https://developers.facebook.com/docs/ios/user-data-ios-sdk/
If you take a look at the JSON that is returned you won't see any likes, so what does that mean? There's no way to fech the likes of a user? Why even bother calling the permission "user_likes"?
Any direction will be very appreciated.
Thanks.
Well, let's put it this way. Facebook documentation is confusing.
To get he user likes you have to use FQL, the snippet, would be something like this.
// Query to fetch the active user's friends, limit to 25.
NSString *query =
#"SELECT page_id, type FROM page_fan WHERE uid = me()";
// Set up the query parameter
NSDictionary *queryParam = #{ #"q": query };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Result: %#", result);
}
}];
This way you are getting the users Pages id. If you need something else, take a look at the documentation here: https://developers.facebook.com/docs/reference/fql/page_fan

Get a users timeline from the Facebook API

I'm currently using this piece of code to get a users feed from Facebook:
FBRequest *friendsRequest = [FBRequest requestWithGraphPath:[NSString stringWithFormat:#"%#?fields=cover,first_name,last_name,relationship_status,feed", self.friendID] parameters:[[NSMutableDictionary alloc] initWithObjectsAndKeys:#"en_EN", #"locale", nil] HTTPMethod:nil];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
postsArray = [[NSMutableArray alloc] initWithArray:[result valueForKeyPath:#"feed.data"]];
[tableView reloadData];
NSLog(#"Data found: %#", [result description]);
NSLog(#"Posts: %i", postsArray.count);
}];
However, this 'feed' also includes things like 'XXX on his own post' or 'User A liked Post B' and I'd like to get just what the user has posted and what others have posted onto his wall (like if you go to a user timeline on facebook.com or in the iOS apps). Is that possible? If not, how can I found out if a status is a 'like' or 'commented on...'?
Why not use the read_stream permission and FQL
Documentation here
You can loop through results and find where type is equal to:
46 - Status update
56 - Post on wall from another user

How to specify the app name user was using to post - (via app name) using SDK 3.1

Using the new Facebook SDK 3.1 and iOS 6 there are 2 (actually 3) ways to post.
(Seems the new trend is to have more options to make it more simple??) OMG!!
Here is one:
SLComposeViewController *fbPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbPost addURL:[NSURL URLWithString:href]];
[self presentViewController:fbPost animated:YES completion:nil];
And this is another way using native dialogs:
[FBNativeDialogs presentShareDialogModallyFrom:self
initialText: nil
image: nil
url: [NSURL URLWithString:href]
handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
}
else
{
switch (result) {
case FBNativeDialogResultSucceeded:
break;
case FBNativeDialogResultCancelled:
break;
case FBNativeDialogResultError:
break;
}
}
}];
We, developers, think this is cool because we give a nice functionality to the user and also because our app name appears in the post and that can make some promotion of the app.
The funny thing is that latest implementations are not allowing to specify the app name was posting, the name appears after 'via'.
I tried aswell using SLRequest:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *fbType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
(options)[#"ACFacebookAppIdKey"] = kFacebookAppID;
(options)[#"ACFacebookPermissionsKey"] = #[#"publish_stream"];
(options)[#"ACFacebookAudienceKey"] = ACFacebookAudienceFriends;
[store requestAccessToAccountsWithType:fbType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *fbAccounts = [store accountsWithAccountType:fbType];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
(params)[#"link"] = href;
// (params)[#"picture"] = picture;
// (params)[#"name"] = name;
(params)[#"actions"] = #"{\"name\": \"Go Gabi\", \"link\": \"http://www.gogogabi.com\"}";
//Set twitter API call
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:#"https://www.facebook.com/dialog/feed"] parameters:params];
//Set account
[postRequest setAccount: [fbAccounts lastObject]];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if(error)
{
NSLog(#"%#", error.description);
}
else
{
NSLog(#"%#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}
}];
} else {
}
}];
Unfortunatelly to share that name is not so trivial anymore, I wonder why and who was designing the new implementation...
I would appreciate to get some help on that, thanks in advance.
I try to make my questions funny because is soo boring spend time in so trivial topics...
When you use the SLComposeViewController, it's actually the system presenting to you their controller, and it's the user who sends using the post button. Therefore on Facebook it appears as "via iOS".
There's no way to change that.
Using the Facebook SDK 3.1, under the hood it is also using the iOS 6 native integration, so when you're calling the FBNativeDialogs, on iOS 6, it's using SLComposeViewController.
Facebook continued to develop their SDK because they provide a couple of nice modules to use "out of the box" - this includes friends list selector etc... But I believe the biggest reason for Facebook to continue supporting their SDK it for backward compatibility. Under the hood if you're not on iOS 6, it falls back to it's library, and if you are on iOS 6, it uses the system integration.
Facebook is a big thing, and now it's natively available a lot of developers will be using it, just like Twitter's integration last year. The problem of course is at that point the developer has the option to drop older iOS support, or... have a lot of duplicate code, in the sense that they will check for SLComposeViewController and if it's not available (iOS 5) then use the old Facebook SDK... You can imagine how this would become very messy very quickly.
So, the Facebook SDK (3.1) is using iOS system Facebook integration if available, or if not, it's own. In a nutshell, unless you really want the Facebook SDK goodies (friend picket to name one), and you're not planning on supporting iOS < 6 then you don't need to worry about their SDK, just use the Social framework.
So, back to your question, there are 3 ways to post to Facebook ? Actually taking into consideration what I mentioned, there are 2 ways in iOS 6: SLComposeViewController or, SLRequest. On older iOS versions, only 1: Facebook SDK.
Since the SLComposeViewController is owned by the system, not your app, it will always share as "via iOS".
On the other hand SLRequest will show your apps name. When you specify an account for your SLRequest, that account was acquired via the ACAccountStore as a result of passing in some options including ACFacebookAppIdKey, which will be used to determine your Facebook apps name to post onto the users feed as part of the post.
Hope this helps.