Facebook permissions to know if a friend uses the same app - ios

I can successfully grab a list of friends with this NSURL, using the permissions "publish_stream":
NSURL *friendsList = [NSURL URLWithString:#"https://graph.facebook.com/me/friends
However, when I try the same thing with an added field, as in this URL:
NSURL *friendsList = [NSURL URLWithString:#"https://graph.facebook.com/me/friends?fields=installed"];
I get an error:
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
So my question is what permissions should I be asking for to make the second URL work?
Bonus question: What URL param do I include to get a small profile pic come back in the same JSON object?
Thanks :)

According to the docs, you it Requires app access_token. However, playing with Graph API Explorer, I could get this info without this permission.
You can take a look at Graph API Explorer to test.
Also, the query on the above link returns the picture field, which will have an URL with the user picture.

Related

Sharing to specific Facebook page using Swift SDK GraphSharer

In my iOS app I'm trying to use the Facebook Swift SDK so that a user can post a URL to a specific Facebook page that they manage.
I've managed to get the following code working - but it only shares the post to my home timeline:
let content = LinkShareContent(url: URL(string: urlString)!)
let sharer = GraphSharer(content: content)
sharer.failsOnInvalidData = true
sharer.completion = {
(result) in
print(result)
}
do {
try sharer.share()
}
catch (let error) {
print(error.localizedDescription)
}
I believe that I need to use the graphNode property to specify the destination page and that the correct format is as follows:
sharer.graphNode = "/\(pageId)"
However, when I set this property before posting, I am getting an error:
failed(Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
I've tried a dozen different formats to specify the node but they all return the same error and I can't find any working examples.
I managed to resolved this issue. It turns out that the graphNode path above is correct but I was looking in the wrong place due to the error message I was getting. Instead I just needed to specify the accessToken parameter.
graphSharer.accesstoken = myPageAccessToken
Note: The access token is not the user's current access token, but an access token you can retrieve when calling the /me/accounts API.
var graphPath = "/me/accounts"
I also then had an issue posting to the page because I had only requested the publish_actions permission. From the documentation, this appears to be suitable but it only worked where I requested further permissions as follows:
loginManager.logIn(withPublishPermissions: ["publish_actions",
"manage_pages", "publish_pages"], ...
Hopefully this will be of use to someone in future. :-)

Google Direction API returns error in iOS

Am using following google direction url
https://maps.googleapis.com/maps/api/directions/json?origin=12.976600,77.599300&destination=12.991491,77.715347&client=gme-company&signature=Fwelfejfcb4bbb3hj5bb=
and its not giving any result
in browser its showing
Unable to authenticate the request. Provided 'signature' is not valid for the provided client ID, or the provided 'client' is not valid.
The signature was checked against the URL: /maps/api/directions/json?origin=12.976600,77.599300&destination=12.991491,77.715347&client=gme-company
If this does not match the URL you requested, please ensure that your request is URL encoded correctly. Learn more: https://developers.google.com/maps/documentation/business/webservices/auth
my method is this
- (void) estimateETAWithWithOrigin:(CLLocationCoordinate2D)origin destination:(CLLocationCoordinate2D)destination onSuccess:(DirectionsCompletionBlock) completionBlock {
NSString *baseUrl = [NSString stringWithFormat:#"%#?origin=%f,%f&destination=%f,%f&client=%#&signature=%#",
GOOGLE_DIRECTIONS_API,
origin.latitude,
origin.longitude,
destination.latitude,
destination.longitude,
CLIENTID,CRYPTO_KEY];
baseUrl = [baseUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"%#",baseUrl);
.....
}
Pls help
You can find information on how to use digital signatures in the developers documentation
You even have a place there to test your signature.
The code for signing a request in Objective C can be found on the google maps github repo

FBSDKGameRequestDialog with FBSDKGameRequestFilterAppNonUsers error

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.

How to get token_for_business for Facebook login - iOS

How can I get token_for_business from Facebook login? I have setup a business and associated my application with that business. Facebook documentation says you need to call GET /me?fields=token_for_business on User node, and it will return following json.
{
"id": "1234567890"
"token_for_business": "weg23ro87gfewblwjef"
}
I tried by providing token_for_business in parameter list of /me call but didn't work. Need advises.
Edit
I found this URL https://developers.facebook.com/docs/graph-api/reference/v2.5/user and tried by passing token_for_business in param of initWithGraphPath but no gain. I checked in Graph API Explorer and getting the required data. But not sure how to call from my objective-C code.
Edit 2
I Inspected the error object of initWithGraphPath:#"me?fields=token_for_business" call and found following details
Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=403, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#200) Application must be associated with a business. https://business.facebook.com/, com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=200, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 200;
"fbtrace_id" = "EN9bN/YMloA";
message = "(#200) Application must be associated with a business. https://business.facebook.com/";
type = OAuthException;
};
};
code = 403;
}}
But if I try my app in Graph API Explorer then I'm getting the required data. So now it confusing me.

Error code 2500 when requesting facebook picture

I am using the social framework and the accounts framework to access facebook from my app. In one line of code I do:
NSURL *meInfo = [NSURL URLWithString:#"https://graph.facebook.com/me"];
Which is successful. I get a json object with me data which I can then use in my app. Confusingly, in the very next block of code, I do this:
NSURL *meInfoPic = [NSURL URLWithString:#"https://graph.facebook.com/me/picture"];
And it fails with:
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
My access token is obviously valid, so I am not sure what is going on. The permissions I am using for both are "publish_stream". Any advice?
My mistake was using /me/ in the picture request URL. Once I replaced that with the user id for the logged in user I got further. So to be clear, I needed to do this:
NSURL *meInfoPic = [NSURL URLWithString:#"https://graph.facebook.com/123456789/picture"];

Resources