iOS Facebook SDK FBRequest requestForMyFriends returning only Test Accounts - xcode6

I'm trying to get all Facebook friends that uses my App.
This is my code:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
_fbIDsArray = NSMutableArray.array;
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.objectID);
[_fbIDsArray addObject:friend.objectID];
}
When I'm working with the Facebook test user it returns friends, but when I try to find friends with a real account it returns nil.
The App Status on Facebook is public.
I'm using Facebook SDK 3.20
UPDATE
This worked for me
FBLoginView * loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends"]];
loginView.delegate = self;
NSArray *permissions = #[#"public_profile", #"email", #"user_friends"];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error)
}];
}];

In the latest Facebook SDK, you can get the list of such friends who is using the app. For more info please refer the following link -
https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference-friends

Related

Getting Facebook user info after login in objective c

I'm trying to get the user name, email and picture from Facebook after login. Login and permissions works fine.
I tried using:
FBSession
But Im getting "user of undeclared FBSession" as I was trying to implement:
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
NSString *firstName = user.first_name;
NSString *lastName = user.last_name;
NSString *facebookId = user.id;
NSString *email = [user objectForKey:#"email"];
NSString *imageUrl = [[NSString alloc] initWithFormat: #"http://graph.facebook.com/%#/picture?type=large", facebookId];
}
}];}
Found it here: How to get user info from Facebook SDK in iOS?
Any ideas how can I achive this? Or why am I getting undeclared for Facebook elements?
If you are using the new facebook sdk and new graph api you have to use access tokens
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:#{#"fields": #"picture,email,birthday,gender,name"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id res, NSError *error)
{
if (!error) {
FBID = [res objectForKey:#"id"];
FBDOB = [res objectForKey:#"birthday"];
FBEMAIL = [res objectForKey:#"email"];
FBGENDER = [res objectForKey:#"gender"];
FBUSERNAME = [res objectForKey:#"name"];
}
else
{
NSLog(#"%#", [error localizedDescription]);
}}];
}
check out this link on fetching data from facebook
https://developers.facebook.com/docs/ios/graph

Twitter Streaming Endpoint not working with SLRequest object

I am trying to pull data from the Twitter Streaming API using the SLRequest class.
When I use the endpoint and parameters documented in the code below the program "hangs"
and no JSON data is printed. I am using an endpoint based on an example from the twitter dev
website https://dev.twitter.com/docs/streaming-apis/parameters#with I am requesting
tweets at a certain location.
When I use this code to query my timeline using the REST API (the code and request is included but
commented out) the program does not hang and I get a valid response.
Is there something else in the code that I need to implement to access the data using the streaming API? What additional modifications or changes need to be made?
ACAccountStore * accountStore = [[ACAccountStore alloc] init];
ACAccountType * twitterAccountType =
[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Ask the user permission to access his account
[accountStore requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == NO) {
NSLog(#"-- error: %#", [error localizedDescription]);
}
if (granted == YES){
/***************** Create request using REST API*********************
***************** This URL is functional and returns valid data *****
NSURL * url = [NSURL URLWithString:#"https://userstream.twitter.com/1.1/user.json"];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:#{#"screen_name": #"your_twitter_id"}];
***************************************************************/
// Create request using Streaming API Endpoint
NSURL * url = [NSURL URLWithString:#"https://stream.twitter.com/1.1/statuses/filter.json"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:#"track" forKey:#"twitter&"];
[params setObject:#"locations" forKey:#"-122.75,36.8,-121.75,37.8"];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:params];
NSArray * twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
if ([twitterAccounts count] == 0) {
(NSLog(#"-- no accounts available"));
} else if ([twitterAccounts count] >0){
[request setAccount:[twitterAccounts lastObject]];
NSLog([request.account description]);
NSLog(#"Twitter handler of user is %#", request.account.username);
// Execute the request
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSError * jsonError = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&jsonError];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// NSLog(#"-- json Data is %#", json);
NSLog([json description]);
}];
}];
}
}
}];
SLRequest doesn't play well with the streaming API.
Here is how to do with STTwitter:
self.twitter = [STTwitterAPI twitterAPIOSWithAccount:account];
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
NSLog(#"-- access granted for %#", username);
[_twitter postStatusesFilterUserIDs:nil
keywordsToTrack:#[#"twitter"]
locationBoundingBoxes:#[#"-122.75,36.8,-121.75,37.8"]
delimited:nil
stallWarnings:nil
progressBlock:^(id response) {
NSLog(#"-- %#", response);
} stallWarningBlock:^(NSString *code, NSString *message, NSUInteger percentFull) {
NSLog(#"-- stall warning");
} errorBlock:^(NSError *error) {
NSLog(#"-- %#", [error localizedDescription]);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- %#", [error localizedDescription]);
}];
Internally, STTwitter builds a NSURLConnection instance with the request from -[SLRequest preparedURLRequest]. You can replicate this trick in your code if you wish.

can not get user info after doing authentication,facebookSDK, ios

I am trying to authenticate using facebook account by following
- (IBAction)logInByFaceBook:(id)sender {
NSLog(#"appDelegate.session.isOpen = %#",appDelegate.session.isOpen == 0 ? #"NO" : #"YES");
FBSessionLoginBehavior behavior = FBSessionLoginBehaviorForcingWebView;
appDelegate.session = [[FBSession alloc] init];
[appDelegate.session openWithBehavior:behavior
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSNumber numberWithBool:YES] forKey:#"didLogIn"];
data = [[SavedData alloc] initLogInInfo:dict];
[data saveLogInInfoToDisk];
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
NSLog(#"me is %#",[me description]);
[me startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *my, NSError *error) {
NSLog(#"my is %#",[my description]);
}
];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
];
}
However, i cant not get my username back and the console is displaying
Error: HTTP status code: 400
my is (null)
By looking up this documentation, 400 means Invalid email address..... and my is null so that I can no extract the username at all.....
I dont know why this happens...I try with the same email address with facebookSDK sample code and it works properly...
Getting lost now....Can somebody point out what I am doing wrong or missing something.

facebook login error at ios

i'm new at iOS, and i want to do a facebook login for my app.
i tried a lot with the new ios sdk of facebook. but i'm getting error.
the code is
-(IBAction)logIn:(id)sender;
{
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appdelegate sessionOpener];
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
NSLog(#"id %#", my.id);
NSLog(#"name %#", my.first_name);
greet.text = my.first_name;//this is a label to show the name
user.userID = my.id;//this is a FBProfilePictureView to show
}];
[UIView transitionFromView:self.view
toView:userPage
duration:0.5
options:(UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionTransitionFlipFromLeft)
completion:NULL]; }
`
and sessionOpener is;
-(void) sessionOpener{
[FBSession sessionOpenWithPermissions:nil
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// session might now be open.
}];
}
now the errors i get is;
when i first log in to app after logging in the values return null
and i get http 400 error.
but after logged in when i run app second time it gets the info true and prints my name.
my simulator iphone 5.1 simulator
Try creating the session object and add it to the request:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"email",
#"publish_stream"
nil];
FBSession facebook_session = [[FBSession alloc] initWithPermissions:permissions];`
[[[FBRequest alloc] initWithSession:facebook_session graphPath:#"me"] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
// get the data from user object
}else {
NSLog(#"Error: %#",error);
}
}];`

Twitter integration and iOS5: semantic and parsing issues

I was using some of Apple's example code to write the Twitter integration for my app.
However, I get a whopping amount of errors (mostly being Semantic and parse errors).
How can this be solved?
-(IBAction)TWButton:(id)sender {
ACAccountStore *accountstore = [[ACAccountStore alloc] init];
//Make sure to retrive twitter accounts
ACAccountType *accountType = [accountstore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountstore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted) [{
NSArray *accountsArray = [accountstore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:[#"Tweeted from iBrowser" forKey:#"status"] requestMethod:TWRequestMethodPOST];
[postRequest setAccount:twitterAccount];
[postRequest preformRequestWithHandeler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i", [urlResponse statusCode]];
[self preformSelectorOnMainThread:#selector(displaytext:) withObject:output waitUntilDone:NO];
}];
}
}];
}
//Now lets see if we can actually tweet
-(void)canTweetStatus {
if ([TWTweetComposeViewController canSendTweet]) {
self.TWButton.enabled = YES
self.TWButton.alpha = 1.0f;
}else{
self.TWButton.enabled = NO
self.TWButton.alpha = 0.5f;
}
}
The first error I see is easy to get rid of.
Objective C convention is to make the first letters of each method name lower case.
Use makeKeyAndVisible in your AppDelegate.m
The other errors we'd probably need to see where (in your code) the errors are being thrown, not just what kind of errors.