Upload photo to Facebook album using user_photos on ios - ios

I'm sure there's something simple I'm missing regarding this, but when using requestForUploadPhoto to send a photo to an album, it gets sent up with permission set to 'Only me'. Because the permission setting is so restrictive, photos then need to be manually approved by the user. Is there a way to alter the default upload permission (which will hopefully stop it requiring manual approval)? Normally it would be set when requesting a publish permission, but because user_photos is technically a read permission, I'm not given the chance to specify this. Code is below.
[FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObject:#"user_photos"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
FBRequest* request = [FBRequest requestForUploadPhoto:uploadImage];
FBRequestConnection* connection = [[FBRequestConnection alloc] init];
[connection addRequest:request completionHandler:^(FBRequestConnection* connection, id result, NSError* error)
{ NSLog(#"Done with upload"); }];
[connection start];
}];
I know it's not even slightly close in terms of catching and managing other session changes, but I'm not fussed with that atm - I just want to get this permission issue resolved before coding the rest.

user_photos only allows you to see photos (using GET), and does not allow you to post a photo. To do that, you need either publish_stream or publish_actions. Are you sure your app didn't already have a publish permission somehow?
You are correct in that the privacy is set when an app requests publish permissions, and the user can change that at any point later on as well (via the Facebook app or website).

Related

Facebook iOS SDK: requestNewPublishPermissions not initializes permissions

I just started using facebook sdk and slightly confused with it documentation. It's well written, but very often does not correspond to current SDK version. So i'm not found what to do with this situation:
I request publish permissions when firstly require them, with the next code:
[[FBSession activeSession] requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (error) {
NSLog(#"Permissions request error: %#", error.description);
}
completion(error == nil);
}];
I need only one publish permission - 'publish_actions', when i request it sdk redirects me to facebook app and immediately returns back to the my app without asking whether i'm agree to give this permission.
There are no errors in completionHandler, but through debug i found that this permission was saved in the variable _requestedReauthPermissions:
So, finally, permission i requested not granted to me.
How properly request publish permission? What could I miss? May it occur due to setup of facebook app?

Facebook iOS SDK 3.x - publish permisisons

Facebook integration in my app works well. I ask for *read_stream* permission at login, then for *publish_actions* when I want to publish anything for the first time (as recommended).
The issue is, that when I ask for *publish_actions* permission, app switches to Facebook app and back. I wouldn't like user to see Facebook app, and I know many apps that post to the wall silently.
How can I do this?
You should ask for publish permission on login, not when publish something for the first time.
Once the user is logged in with all needed permission, he won't see the fb app screen again (unless the session expired or is closed).
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:aCompletionHandler];
if You did ask about public_action in the first time user login you not need it again. U need check active permission. If public_action found you not need call to get it a gain
// Ask for publish_actions permissions in context
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
// Permission hasn't been granted, so ask for publish_actions
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (FBSession.activeSession.isOpen && !error) {
// Publish the story if permission was granted
// write your code public here
}
}];
}
else {
// If permissions present, publish the story
// write your code public here
}

How is FBSession used

I'm integrating facebook and I still don't see how the FBSession ties everything together.
This is how I think it works.
You need a new FBSession each app launch. (Is this true?). The FBSession also needs to be closed every time the app stops (if this is true, how do we start a new session without asking user to login again?)
As far as the session is concerned, [FBSession activeSession] is a global managed by the facebook sdk? Should we just use this as the default session anytime we want to pull data or check if a session is alive?
Assuming the above logic has worked out and you get the user id (fb id) then we feed that id to a FBImageView and we get a profile pic, but isn't this id changing every launch? So storing it on our server isn't helpful? Should we get the id every launch?
Please let me know what is right or wrong about the above statements, and an explanation of why?
Thank you.
I suggest you to use activeSession of FBSession. This way you don't have to create sessions yourself. Just use [FBSession openActiveSessionWithReadPermissions:...] method of FBSession for activating activeSession, and on successful opening, You could use FBSession.activeSession for your Facebook requests. Good luck!
PS>
In order to restore activeSession you can do:
if (![FBSession.activeSession isOpen]) {
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info"] allowLoginUI:NO completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
}];
}
which will open the session if it has cached token information without showing login UI.

read and publish permission in facebook sdk 3.0 iOS

In the last SDK, read and publish permissions are separated. So, in my code, whenever the users logs in I am using this code:
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
I have seen in the facebook developer that when I want to publish, I should ask for publish permissions like this:
// can include any of the "publish" or "manage" permissions
NSArray *permissions =
[NSArray arrayWithObjects:#"publish_actions", nil];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
/* handle success + failure in block */
}];
Since this is my first app that I am using facebook integration, I want to ask a couple of things:
1) Can these sessions be open at the same time? I will ask for the publish permissions only when the user wants to publish, but should I do something else with the other session? Like close it first, and reopen it later or I should not worry about?
2) If I have a postToFriends button for example, my pseudocode for making it work would be like this, right?
- (IBAction)postToFriendaction:(id)sender {
if (!FBSession.activeSession.isOpen) {
/* code from the above for enabling publish permissions*/
}
or I should change !FBSession.activeSession.isOpen to something else, because no the user is logged in with read permission only, he never enters the if clause. Can you help me?
The two sessions you refer to are actually the same session (it's the "active" session that's statically available after a call to openActiveSession... is called). So you don't need to do anything with the other session.
You should have a look at either the Scrumptious or Hello Facebook sample apps that ship with the SDK. They both give examples on how to post (while asking for publish permissions).

Facebook iOS Error Login Dialog Write privacy is not specified

Has anyone solved this error message when a user is in the login flow? I tried to toggle my default privacy settings in DevCenter -> Permissions.
I am using the deprecated method in order to both get read and right permissions at the same time. I have other apps successfully using this method.
- (void)openSession
{
[FBSession openActiveSessionWithPermissions:[[NSArray alloc] initWithObjects:#"email",#"publish_actions",#"user_birthday", nil] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session state:status error:error];
}];
}
I've already replied to your bug report on our developer website(https://developers.facebook.com/bugs/568170979870794).
If you're entering the FacebookDisplayName in your .plist file, it will opt you in for read-write permissions split. What this means is that you can no longer request read/write permissions together(using our deprecated openActiveSessionWithPermissions call). This is not a breaking change but is by design.
Set sandbox mode to no in your application settings in facebook.
I was able to fix this by removing the newly added FacebookDisplayName property ( as of FB SDK 3.5) from the *.plist file.
Opened a bug # facebook:
https://developers.facebook.com/bugs/568170979870794

Resources