Get Logged In FB User's albums - ios

I get an empty array when I request logged in facebook user's photo albums. Following is the code:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:#"me/albums"]
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Results: %#",result);
}];
NSLog results:
Results: {
data = (
);
While logging in, I have set the permissions as #"basic_info",#"user_photos",#"friends_photos"
Here is code to log in:
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:#[#"basic_info",#"user_photos",#"friends_photos"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
[appDelegate getFacebookUserInfo];
NSLog(#"Granted Perm: %# Declined Perm: %#",[result grantedPermissions],[result declinedPermissions]);
}];
The NSLog prints:
Granted Perm: {(
email,
"contact_email",
"public_profile"
)} Declined Perm: {(
)}

When Logging in #"friends_photos" is not needed.
#"user_photos" permission will do the job
As per Facebook's official documentation:
If your app requests this permission Facebook will have to review how your app uses it.
That is the reason, #"me/albums" returned empty array. Meanwhile, your app goes for review to Facebook, you can get a user's album. But the user must be one of users in your Facebook App Dashboard's Roles section.

Related

iOS :Unable to get Facebook profile public data as media (Images & video)

I integrated FB account in my iOS mobile Application and it's approved by FB, But when any user logged in with FB login then only basic details coming successfully but unable to get the logged in User's media (Images/Video which uploaded by him as public)
I already mentioned the permission
"let facebookReadPermissions = ["public_profile","email","user_birthday","user_photos","user_videos"]"
Also i logged out from mobile safari and did fresh login but no luck.
After long search i am not able to fix this issue, Please help me.
You can try the Facebook Graph API. Check the code given below....
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
If you are taking the permission in FB login than for getting the data you should use this code after successful login to FB.
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me"
parameters:#{ #"fields": #"id,name,photos,videos,email,picture,birthday",}
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
}];

How to get user's albums id using facebook sdk in iOS

I m using Facebook SDK version 4.16 and working on iOS 9.3
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:#"/%#/albums",[result objectForKey:#"id"]]
parameters:#{#"fields":#"albums"}
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
NSLog(#"%#",result); // got success message
}
}];
I did set "user_photos" in permission at the time of user Facebook login.
In above code [result objectForKey:#"id"] this line gives Facebook user id.
but this code returns me an empty array for key data hence i am not getting album id and other details.

Facebook Graph API : how to get group cover image source in FB ios SDK

I ma trying to get Group cover image source through Graph API but unfortunately i am getting nil value with public_profile permission and invalid scope error with user_groups permission.
I have checked following Facebook documentation :
FB Group reading
FB Cover photo
FB Permission
First I tried with [login logInWithReadPermissions:#[#"public_profile"] permission later I found that I need to used user_groups. when I have used [login logInWithReadPermissions:#[#"user_groups"] getting following scope error
I have tried following code
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:#[#"user_groups"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
FBSDKAccessToken *accessToken = [FBSDKAccessToken currentAccessToken];
NSDictionary *params = #{#"access_token" : accessToken};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/190520617800186?fields=source"
parameters:params
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Success");
}];
}
}];
I have already submitted a request for Facebook app review

Facebook SDK v4 + Parse 1.7.5 issue

I've updated my SDKs from Facebook and Parse to the newest ones which includes some change in the PFFacebookUtils structure.
I would like to create a PFUser with some content from FB. It have been working for a long time before the update, but now when I log in, I only receive the user's name and FBID as result from the Facebook request.
This is how "I" log in:
NSArray *permissionsArray = #[#"public_profile", #"email", #"user_education_history", #"user_work_history", #"user_birthday", #"user_friends", #"user_photos"];
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissionsArray block:^(PFUser *user, NSError *error) { ... }];
This is how I try to get the results:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"Result %#", result);
...
}];
The log only shows this:
2015-08-03 01:41:15.039 XXXXXX[10807:2640469] Result {
id = 1015XXXXXXXXXXXX;
name = "Simon XXXX";
}
The Facebook App ID is set in the pList.
The latest Facebook SDK uses the Graph API v2.4, so the special me request needs the specific fields as query parameters to the graph path.
So, if you need to access the first, last name and email, the graph path in your code would look something like this:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me?fields=first_name,last_name,email" parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"Result %#", result);
...
}];
I also suggest that you check out and play with the Graph API Explorer (note the API version dropdown in the top right corner).

Fetching facebook friends of user

I am trying to fetch facebook friend list of the user but it returning only count of the friends.Bellow is my code .Is there anything wrong in this code?
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"me/friends result=%#",result);
NSLog(#"me/friends error = %#", error.description);
NSArray *friendList = [result objectForKey:#"data"];
//[m_allFriends addObjectsFromArray: friendList];
}];
}
When you registered your app to facebook. Facebook provide only three permission , these permission is by default approved
user_friends Provides access to a person's list of friends that also use your app. This permission is approved by default.
according to this you can get only those friend who use your app.
check this link
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends

Resources