FBSDKGameRequestDialog with FBSDKGameRequestFilterAppNonUsers error - ios

I need to implement game invitations (ie. inviting friends who are not users of the app to try the app) on an iOS app (which already has a working Facebook login system). There seems to be several possible ways of doing this, each with their own different requirements. FBSDKGameRequestDialog seems like a promising way of doing this. The tutorial at https://developers.facebook.com/docs/games/services/gamerequests says:
"Alternatively, by specifying app_non_users, the sender will only see friends who have previously not authenticated the app. This should be used when using requests for inviting new users to the game."
This seems to be exactly what I'm looking for. I therefore tried this:
FBSDKGameRequestContent* content = [[FBSDKGameRequestContent new] autorelease];
content.actionType = FBSDKGameRequestActionTypeSend;
content.filters = FBSDKGameRequestFilterAppNonUsers;
content.message = #"something";
content.title = #"something";
content.objectID = #"1"; // No idea what to put here
FBSDKGameRequestDialog* dialog = [[FBSDKGameRequestDialog new] autorelease];
dialog.content = content;
dialog.delegate = self;
NSError* error = nil;
if(![dialog validateWithError: &error])
NSLog(#"%#", error);
else
[dialog show];
The dialog launches, but calls the delegate with an error, namely:
Error Domain=com.facebook.sdk.share Code=100 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Invalid fbid.}
That error message is not very helpful, nor can I find anywhere why it's happening, or what the exact requirements are for this to be possible. (Yes, I am logged successfully into Facebook. Everything else is working just fine. I have no idea where that "Invalid fbid" is coming from.)
The same tutorial page offers an alternative to do this, by requesting a list of invitable friends explicitly, and using your own GUI. However, it says:
"This feature is only available to games with a presence on Facebook Desktop"
Obviously it doesn't bother telling what that means, or give a link to further information. And of course making the request doesn't work. (The error says "please set a Canvas URL in your app's settings", which I have no idea what it means or how to do it, even after browsing Facebook's own documentation and googling.)
Either way, I would prefer the SDK's own dialog for this, as it's much less work.

objectId refers to the "Open Graph object ID of the object being sent.". Lets say I am sending you 100 Coins of your in-app currency, then this would be the ID of the object you created for that "gift".
You don't have to provide a value for it if you are not planning to send around in-game items, and in your example, 1 is obviously not a valid ID for an object. The message could be more descriptive though.

Related

How can I receive update status(data) when I request ride with UBSDKRideRequestViewController (Uber SDK)

I have added Uber SDK in my application. I didn't request project to Request full access. It's on development. and I have issues that I can't find an answer (I'm using sandbox mode.)
Q. I need to test. If I requested and driver is already accepted. How can I know the time that he will arrive or other status e.g.arrived . and How can I send notification to my user in my application when driver is arrived. I see UBSDKRideRequestViewControllerDelegate response only error case.
this's my code.
UBSDKRideParametersBuilder *builder = [[UBSDKRideParametersBuilder alloc] init];
[builder setPickupToCurrentLocation];
[builder setDropoffLocation:dropoffLocation];
UBSDKRideParameters *parameters = [builder build];
NSArray<UBSDKRidesScope *> *scopes = #[UBSDKRidesScope.RideWidgets,UBSDKRidesScope.Profile,UBSDKRidesScope.Request];
UBSDKLoginManager *loginManager = [[UBSDKLoginManager alloc] init];
UBSDKRideRequestViewController *vc = [[UBSDKRideRequestViewController alloc] initWithRideParameters:parameters loginManager:loginManager];
vc.title = #"Uber";
vc.delegate = self;
please advice thanks.
Currently, the Ride Request Widget does not provide you notifications for changes in trip status. You can, however, get the status of the current trip by using a RidesClient and calling fetchCurrentRide which will give you details about the current trip. In order to access trips from the widget on this endpoint, however, you will need the all_trips scope. This will require you to handle login separately from the RideRequestViewController. You can use the LoginButton or LoginManager to request the AllTrips and RideWidgets RidesScopes
In terms of testing, you can update the status of a sandbox trip by making a PUT request to the /v1/sandbox/requests/{request_id} endpoint with a JSON body in the form {"status": "accepted"} (replacing the status you want to see). This status change would then be reflected in your app. You can find more information on the sandbox on the Uber Developer Site

iOS OneDrive (skydrive) app displays permissions dialog every time it runs

I'm developing an iOS app that gives users access to their OneDrive/SkyDrive and I've run into a very annoying issue:
The very first time a user links the app to their OneDrive, everything goes as expected:
They have to enter a user id and password
Then they have to agree to let the app access their info
Then they get to browse their OneDrive
That's all good.
But, if the app closes, and you try to access the OneDrive again, rather than skipping straight to #3, and being able to access the OneDrive, they are stopped at step #2 (step 1 is skipped, as expected) and they have to agree again to let the app access their info.
The code is taken directly from the iOS examples in the online documentation (with some slight modification based on samples found here on Stack Overflow), but, here it is for inspection:
- (void) onedriveInitWithDelegate:(id)theDelegate {
self.onedriveClient = [[LiveConnectClient alloc] initWithClientId:MY_CLIENT_ID
delegate:theDelegate
userState:#"initialize"];
}
And then, theDelegate implements this:
- (void)authCompleted:(LiveConnectSessionStatus) status
session:(LiveConnectSession *) session
userState:(id) userState {
NSLog(#"Status: %u", status);
if ([userState isEqual:#"initialize"]) {
NSLog( #"authCompleted - Initialized.");
if (session == nil) {
[self.onedriveClient login:self
scopes:[NSArray arrayWithObjects:#"wl.basic", #"wl.signin", #"wl.skydrive_update", nil]
delegate:self
userState:#"signin"];
}
}
if ([userState isEqual:#"signin"]) {
if (session != nil) {
NSLog( #"authCompleted - Signed in.");
}
}
}
I thought that perhaps the status value might give a clue and that maybe I could avoid the login call, but it's always zero/undefined when I get to authCompleted after calling initWithClientId. (And session is always nil.)
Is there a scope I'm missing? Is there a different call to make rather than a straight-up login call? Or is it more complicated than that? I've seen reference to "refresh tokens" related to OAuth2 login, but I've not been able to find any concrete examples of how they might be used in this situation.
Any help and/or insights greatly appreciated.
Diz
Well, it turns out that the answer is pretty simple here. I just needed to add the "wl.offline_access" scope to my list of scopes during the initial login operation. The docs didn't really imply this type of behavior for this scope, but, that did the trick for me.
With this new scope added, subsequent invocations of the app no longer bring up the "agree to give the app these permissions" dialog, and I can go straight to browsing the OneDrive.
(Credit where it's due: Stephane Cavin over at the microsoft forums gave me the tip I needed to work this out. Gory details are here:
http://social.msdn.microsoft.com/Forums/en-US/8c5c7a99-7e49-401d-8616-d568eea3cef1/ios-onedrive-skydrive-app-displays-permissions-dialog-every-time-it-runs?forum=onedriveapi )
Diz

Facebook iOS Select Friends Table Blank

I am trying to add the "select friends" to my iOS app. I set up the login view. Once I login I open the friend picker but it comes up blank. I see the table with the done and cancel buttons but there are no friends loaded into the table.
- (IBAction)selectFriendsButtonAction:(id)sender {
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = #"Select Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentViewController:self.friendPickerController animated:YES completion:nil];
}
Prior to opening the friend picker controller ensure your Facebook session is active by calling this:
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
// Handle error
}];
}
There's two things you need to take care of that you may well not realize you need even if you understand the rest of the Facebook SDK pretty well.
The dialog will only show friends that have also installed the app.
You have to ask for the user_friends permission during your login flow.
For 1., create or use a test user you already have and run your app with that user in order to authorize the app for basic access ("install" it).
For 2, add that permission to your login flow, log out and back in with the sender you're testing (probably your own user), and if you don't get prompted to grant it even then, uninstall the app via https://www.facebook.com/settings/?tab=applications.
http://www.brianjcoleman.com/tutorial-get-facebook-friends-in-swift/ discusses some of this. The Facebook docs themselves either don't mention the 2 issues at all or it's buried.
If you use "FBFriendPickerViewController", it seems return friends who also use this APP. In Facebook document: after API Graph v2.0, "me/friends" will only return friends that also use the app. I think that's why the friend table is blank.
There is another option that you can use "FBTaggableFriendPickerViewController" instead. But your APP will need to be reviewed by Facebook before it can get data back. (https://developers.facebook.com/docs/graph-api/reference/v2.2/user/taggable_friends?locale=zh_TW)

ios-Facebook SDK 3.0 Error 5 When Posting Status Update

I am trying out adding facebook integration in an app using the new (beta) facebook ios sdk 3.0. All I would like to is post a status update to facebook. I used a FBLoginView to login to facebook. I put my app id in the plist as instructed on facebook. I put in some code to post to facebook.
(void)viewDidLoad
{
[super viewDidLoad];
NSArray *perms;
perms = [NSArray arrayWithObjects:#"status_update", nil];
FBLoginView *loginview =
[[FBLoginView alloc] initWithPermissions:perms];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)poststatus:(UIButton *)sender {
NSString *message = [NSString stringWithFormat:#"Test staus update"];
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:message result:result error:error];
}];
}
- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error {
NSString *alertMsg;
NSString *alertTitle;
if (error) {
alertMsg = error.localizedDescription;
alertTitle = #"Error";
} else {
NSDictionary *resultDict = (NSDictionary *)result;
alertMsg = [NSString stringWithFormat:#"Successfully posted '%#'.\nPost ID: %#",
message, [resultDict valueForKey:#"id"]];
alertTitle = #"Success";
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
The odd thing is, this code works ONCE. After authenticating the user for the first time, I can post ONE status update successfully. After that, all subsequent attempts will fail with a FBiOSSDK error 5 (in the console, Error: HTTP status code:400). The only way to fix this is to remove the app from the facebook account and re-authenticate. I'm not sure what the problem is. I looked online for solutions but couldn't find anything. If anyone knows how to fix this, please let me know. Thanks
com.facebook.sdk error 5 is always irritating while working with Facebook iOS sdk. Most of the times it comes with addional in console Error: HTTP status code:400. Its a perception that there is a bug in Facebook iOS sdk that produces this error randomly. I think this error occurs for some certain reasons and sdk do not provide actual reason of error when it occurs.
Several Possible Reasons
Every request in sdk is accomplished with completion blocks that we actually pass as argument in completionHandler. This error occurs when a block is in progress and made another request. A simple example might be If you have written request to post on Facebook (startForPostStatusUpdate::) on some button action. On single button tap it would work fine but if you double tap on button it will throw this error com.facebook.sdk error 5
If you are trying to post when your current session is not opened. e.g. Once sign in with Facebook then kill the app then reopen and then try to share on Facebook, Result -> com.facebook.sdk error 5. In this case try to reopen session using
Facebook do not allow same status to be posted repeatedly, they think it might be some kind of spam e.g. If you are trying to update status and you have hard coded a string lets say #”This is a test status update” you are posing again and again. After 5 to 10 attempts they wont allow you to do anymore. Resulting com.facebook.sdk error 5. If this is the scenario you should change your status string and try updating.
Facebook has defined a limit for a particular user to post status using sdk. e.g If you are trying to update status and you have done lets say 15 to 20 status updates. They wont let you do more Resulting -> com.facebook.sdk error 5. In this scenario try to unauthorize the app from your Facebook account and reauthorize it OR try using other Facebook account
It seems there might be no answer to the issue. I have checked FB samples coming with SDK, in these examples also the same error happens. So it means after few status updates (15-20) Facebook reaches limits for that particular user. If you log-out for that user and log-in as another user, you can successfully post.
If I will find any extension to limit settings I will reply.
Also Facebook doesn't allow for the same Post.
Use a proxy !
FB ios SDK is just a wrap to an HTTP request to graph.facebook.com/....?access_token=.....
So you can easily replicate the request or use an HTTP proxy to see the real server answer (which is not error 5 !).

Can't get the Facebook publish_action permission on iOS

I've spent hours on this and can't get it to work. Basically I just want a button in my app that will 'Like' itself on Facebook.
I've created the app on dev Facebook and have an associated App Page.
In my code I request these permissions:
_permissions = [NSArray arrayWithObjects:#"publish_stream", #"publish_actions", #"user_birthday", nil];
I can retrieve a profile picture fine, but when I try to 'Like' using this code:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_facebook.accessToken, #"access_token",
nil];
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andParams:params andHttpMethod:#"POST" andDelegate:self];
I get this error response:
(facebookErrDomain error 10000.)" UserInfo=0x20090590 {error={
code = 200;
message = "(#200) Requires extended permission: publish_actions";
type = OAuthException;
}}
When logging in on the app, Facebook asks me for permission to see my birthday, and tell's me it will Post on my behalf but it seems to not get the publish_actions permission.
Is there something i'm missing that I need to do?
I see Temple Run has a Facebook Like button and offers bonus coins for pressing it. This is what I wish to achieve.
EDIT -------
I've changed my permissions to just #"publish_actions", #"user_birthday" and now the auth dialogue says
"This app may post on your behalf, including objects you liked and
more"
which seems to be the publish_actions permission, however I was still getting the error
message = "(#200) Requires extended permission: publish_actions";
I've changed this line:
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andParams:params andHttpMethod:#"POST" andDelegate:selrf];
to this:
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andDelegate:self];
and I do now get a response back, although it doesn't post a 'like'
This is the result response:
{
data = (
);
paging = {
next = "https://graph.facebook.com/329756493773381/og.likes?sdk=ios&sdk_version=2&access_token=BAAGeAp3ZBGwoBAPICjlgB5zK0YECyP8yElf8hJoMrx8Qs4vjeZAK5PlXFAVbGM1JyXHE0wZBvU0aBeCzCUTZBejQgoJ44CAIQsrG64TfrHdxjMqWD&format=json&offset=25&limit=25";
};
}
Any idea what to try next?
EDIT 2 ---------------
I'm making progress with this.
I've added the users id to the graph request like this
NSString *graphPath = [NSString stringWithFormat:#"%#/og.likes",facebookID];
and used these parameters
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"AAAGeAp3ZBGwoBABvKjsPZAoQQNG9cDPJI2v2TI8acyyPSNtm9ZBkfydHqVZAjSKWSbLuvFwxyxSrCts7kFZCnh7Y6f5PFNlWb6smF8XF33wlRZBgfLyhT1", #"access_token",
#"http://samples.ogp.me/329756493773381", #"object",
nil];
and now I get a like showing up on my timeline :-)
I was using the access-token supplied by the Facebook login, but it seems the one supplied by the graph object is different.
Now, the like that i'm seeing has this pattern:
Darren likes object on MyAPP
Is it even possible to have it as
Darren likes MyAPP
with it linking to the app Facebook page?
Thanks
Check if you have done the steps below:
https://developers.facebook.com/docs/opengraph/tutorial/
"Note: The user-prompt for this permission will be displayed in the first screen of the Enhanced Auth Dialog and cannot be revoked as part of the authentication flow." - link
Try this if you havent already:
Auth Dialog -> Configure how Facebook refers users to your app - > Add publish_actions permissions.
https://developers.facebook.com/docs/opengraph/authentication/
"To enable the new Auth Dialog, go to the App Dashboard, and enable the Enhanced Auth Dialog setting in the Advanced section of your app." -link
Hope this helps!
This seems to be the same problem I was having on this SO question:
Facebook iOS SDK 3.0, implement like action on a url?
But if you want to like you facebook page in the app, there is no way to do that in Objective C. Only with the javascript Like button which you can generate here:
https://developers.facebook.com/docs/reference/plugins/like/
The way Temple Run does it is to display the Like button in a web-view, so their like button is actually on their server, this is perhaps an ugly-hack but will work for liking a page.

Resources