Has anyone implemented facebook Notification API in iOS??
I have used it in android its working but for iOS its giving OAuthException.
Its in Beta could be a bug in Notification API??
I am using facebook SDK for iOS v 3.18.
Code
NSString *notification_Id = [NSString stringWithFormat:#"/%#/notifications", friend];
NSString *app_token = #"APP_ID|APP_SECRET";
NSDictionary *dict_notification = #{#"href": url,
#"template": #"You have been invited to Choozr Poll by",
#"access_token" : app_token};
/* make the API call */
[FBRequestConnection startWithGraphPath:notification_Id
parameters:dict_notification
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
if (error) {
NSLog(#"error: %#", error);
}
NSLog(#"%#",result);
}];
Response from facebook
{ > error = { > code = 15; > message = "(#15) This method must be called with an app access_token."; > type = OAuthException; > }
You need to implement the Facebook notification API on your server side code, not the client.
Related
I want to make live video stream from my IOS app to Facebook. I have two facebook account: first - with registered iOS app, second account - only for the test. If I log in with my first account(in my iOS app) - I get the required rtmp://rtmp-api.facebook.com:80/rtmp URL and secret key for the streaming (everything as stated on the FB documentation: https://developers.facebook.com/docs/videos/live-video-api). But if I'm using second account for login, I'm receiving this error:
com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 100;
"fbtrace_id" = Ed9BmMChIsn;
message = "(#100) No permission to perform current operation.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400,
My code for live streaming:
- (void)enableFacebookLiveStreamingWithCompletionHandler:(void(^)(NSString* facebookStreamURL, NSString* facebookStreamKey, NSError* error))completionHandler;
{
dispatch_async(dispatch_get_main_queue(), ^{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:permissionPublishActions])
{
NSString* liveVideosRequestPath = [NSString stringWithFormat:#"/%#/live_videos",[FBSDKAccessToken currentAccessToken].userID];
FBSDKGraphRequest* request = [[FBSDKGraphRequest alloc] initWithGraphPath:liveVideosRequestPath parameters:nil HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"%#",[FBSDKAccessToken currentAccessToken].permissions);
if (error)
{
if (completionHandler)
completionHandler(#"",#"",error);
}
else
{
if (completionHandler)
completionHandler(#"rtmp://rtmp-api.facebook.com:80/rtmp/",[[result objectForKey:#"stream_url"] lastPathComponent],nil);
}
}];
}
});
}
P.S// Very interesting that even though I have included all the permissions here: https://developers.facebook.com/tools/explorer, all the same to me denied access for second account for testing(on which the application is not registered)!
Help me please.
Most permissions need to get reviewed by Facebook, else you can only use them as users with a role in the App. Read about "Login Review" in the docs: https://developers.facebook.com/docs/facebook-login/review
I am using iOS sdk v3.18.1, I want to get all my Facebook friends.I can get the friends count but, data is nil.
Here is my code
[FBRequestConnection startWithGraphPath:#"me/friends" parameters:nil HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"result %#",result);
}];
Out put
{
data = (
);
summary = {
"total_count" = 840;
};
}
https://developers.facebook.com/docs/apps/changelog
Since v2.0 you cannot get the full friend list anymore, you only get the friends who authorized your App too.
See my answer in this thread too: how to get a list of all user friends (not only who use the app)?
// declare an array in header file which will hold the list of all friends -
NSMutableArray * m_allFriends;
// alloc and initialize the array only once
m_allFriends = [[NSMutableArray alloc] init];
With FB SDK 3.0 and API Version above 2.0 you need to call below function (graph api with me/friends)to get list of FB Friends which uses the same app.
// get friends which use the app
-(void) getMineFriends
{
[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];
}];
}
Note : 1) The default limit for the number of friends returned by above query is 25. 2)If the next link comes in result, that means there are some more friends which you will be fetching in next query and so on. 3)Alternatively you can change the limit (reduce the limit, exceed the limit from 25) and pass that in param.
////////////////////////////////////////////////////////////////////////
For non app friends -
// m_invitableFriends - global array which will hold the list of invitable friends
Also to get non app friends you need to use (/me/invitable_friends) as below -
- (void) getAllInvitableFriends
{
NSMutableArray *tempFriendsList = [[NSMutableArray alloc] init];
NSDictionary *limitParam = [NSDictionary dictionaryWithObjectsAndKeys:#"100", #"limit", nil];
[self getAllInvitableFriendsFromFB:limitParam addInList:tempFriendsList];
}
- (void) getAllInvitableFriendsFromFB:(NSDictionary*)parameters
addInList:(NSMutableArray *)tempFriendsList
{
[FBRequestConnection startWithGraphPath:#"/me/invitable_friends"
parameters:parameters
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"error=%#",error);
NSLog(#"result=%#",result);
NSArray *friendArray = [result objectForKey:#"data"];
[tempFriendsList addObjectsFromArray:friendArray];
NSDictionary *paging = [result objectForKey:#"paging"];
NSString *next = nil;
next = [paging objectForKey:#"next"];
if(next != nil)
{
NSDictionary *cursor = [paging objectForKey:#"cursors"];
NSString *after = [cursor objectForKey:#"after"];
//NSString *before = [cursor objectForKey:#"before"];
NSDictionary *limitParam = [NSDictionary dictionaryWithObjectsAndKeys:
#"100", #"limit", after, #"after"
, nil
];
[self getAllInvitableFriendsFromFB:limitParam addInList:tempFriendsList];
}
else
{
[self replaceGlobalListWithRecentData:tempFriendsList];
}
}];
}
- (void) replaceGlobalListWithRecentData:(NSMutableArray *)tempFriendsList
{
// replace global from received list
[m_invitableFriends removeAllObjects];
[m_invitableFriends addObjectsFromArray:tempFriendsList];
//NSLog(#"friendsList = %d", [m_invitableFriends count]);
[tempFriendsList release];
}
For Inviting non app friend -
you will get invite tokens with the list of friends returned by me/invitable_friends graph api. You can use these invite tokens with FBWebDialogs to send invite to friends as below
- (void) openFacebookFeedDialogForFriend:(NSString *)userInviteTokens {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
userInviteTokens, #"to",
nil, #"object_id",
#"send", #"action_type",
actionLinksStr, #"actions",
nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Hi friend, I am playing game. Come and play this awesome game with me."
title:nil
parameters:params
handler:^(
FBWebDialogResult result,
NSURL *url,
NSError *error)
{
if (error) {
// Error launching the dialog or sending the request.
NSLog(#"Error sending request : %#", error.description);
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
NSLog(#"User canceled request.");
NSLog(#"Friend post dialog not complete, error: %#", error.description);
}
else
{
NSDictionary *resultParams = [g_mainApp->m_appDelegate parseURLParams:[url query]];
if (![resultParams valueForKey:#"request"])
{
// User clicked the Cancel button
NSLog(#"User canceled request.");
}
else
{
NSString *requestID = [resultParams valueForKey:#"request"];
// here you will get the fb id of the friend you invited,
// you can use this id to reward the sender when receiver accepts the request
NSLog(#"Feed post ID: %#", requestID);
NSLog(#"Friend post dialog complete: %#", url);
}
}
}
}];
}
Since, V2.0 of the Graph API, You will only be able to get the list of the friends who are connected with your app. In v2.0 of the Graph API, calling /me/friends returns the person's friends who use the app. Yes it is possible to get the count but accessing the friend list is not possible.
All the release of Facebook SDK after the month of April denies this functionality of getting the whole list of friends.
REFER : SO QUESTION:Facebook graph API returns empty .... FACEBOOK USER GUIDE
This has been confirmed by FACEBOOK.
We are trying to create Facebook test users using the Facebook iOS SDK 3.14.1 according to their website: https://developers.facebook.com/docs/graph-api/reference/v2.0/app/accounts/test-users
Here is our code:
NSString *fbAccessToken = [NSString stringWithFormat:#"%#",FBSession.activeSession.accessTokenData];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"true", #"installed",
fbAccessToken, #"owner_access_token",
nil
];
NSString *path = [NSString stringWithFormat:#"/%#/accounts/test-users", kFacebookID];
/* make the API call */
[FBRequestConnection startWithGraphPath:path ///{app-id}/accounts/test-users"
parameters:nil
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
if (result && !error)
{
NSLog(#"Test-User created successfully: %#", result);
}
else
{
NSLog(#"Error creating test-user: %#", error);
NSLog(#"Result Error: %#", result);
}
}];
When we run it we receive the following error:
error = {
code = 15;
message = "(#15) This method must be called with an app access_token.";
type = OAuthException;
};
We have also tried without the parameter owner_access_token but the same error occurs.
How can we create Facebook Test users programmatically using the Facebook iOS SDK?
Solution:
Instead of using the active session access token in you should use the App Token.
Just replace FBSession.activeSession.accessTokenData with your App Token.
The App Token can be found here:
https://developers.facebook.com/tools/accesstoken/
As per WizKid comment above, this is for testing purposes only.
I m using Facebook SDK v3.11.1.
In my app, after i open a session, i look for some information view FQL query:
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:#"SELECT uid, name, can_post FROM user WHERE uid = me()"
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSString* resultString = [NSString stringWithFormat:#"NativeBridge.resultForCallback(mycallback, '%#');", result];
[self.myWebView stringByEvaluatingJavaScriptFromString:resultString];
}
}];
}
I try to invoke javaScript method in my UIWebView.
The object NativeBridge and the method resultForCallback are fine (checked in chrome devTool).
My problem is the parameter result which is actually FBGraphObject.
I try to send to javaScript parameter like:
{
data = (
{
"can_post" = 1;
name = "firstName lastName";
uid = 000000000000000;
}
);
}
But the javascript refuse to get this parameter.
Any help will be great!
Thanks in advance.
I've integrated with Facebook so that I can, among other things, post statuses to my feed. I based some of my code off of the publish to feed developer tutorial. When running the following Graph API request from my iOS application the completion block of the request is never called and no error appears in the XCode debug log.
[FBRequestConnection
startWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error) {
DLog(#"error: domain = %#, code = %d", error.domain, error.code);
} else {
DLog(#"Posted action, id: %#", result[#"id"]);
}
}];
I have two convenience functions that perform checks against the current activeSession before executing this request. They look like this:
+ (BOOL)facebookSessionIsOpen {
return (FBSession.activeSession.isOpen);
}
+ (BOOL)facebookSessionHasPublishPermissions {
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound ||
[FBSession.activeSession.permissions indexOfObject:#"publish_stream"] == NSNotFound ||
[FBSession.activeSession.permissions indexOfObject:#"manage_friendlists"] == NSNotFound) {
return NO;
} else {
return YES;
}
}
Both of these functions return YES indicating an active session with the necessary publishing permission. What's more confusing is that I can pull the user's profile without issue after performing the same checks successfully (granted publishing permissions are not required to pull the profile) using the following code:
[FBRequestConnection
startWithGraphPath:#"me"
parameters:[NSDictionary dictionaryWithObject:#"picture,id,birthday,email,location,hometown" forKey:#"fields"]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSDictionary* resultDict = (NSDictionary*)result;
NSString* emailAddress = resultDict[#"email"];
NSString* location = resultDict[#"location"][#"name"];
NSString* birthday = resultDict[#"birthday"];
NSString* homeTown = resultDict[#"hometown"][#"name"];
...
}];
Any suggestions on how to debug this issue?
Turns out the issue was a threading one. The Facebook iOS SDK doesn't seem to like to execute a FBRequest on a different thread from the one that you called openActiveSessionWithReadPermissions on and promptly deadlocks. It turns out I was running the postStatus request in a separate thread like so:
dispatch_queue_t some_queue = dispatch_queue_create("some.queue.name", NULL);
dispatch_async(some_queue, ^{
[FacebookHelper postStatusToFacebookUserWall:newStatus withImage:imageData];
}];
Make sure your openActiveSessionWithReadPermissions and any FBRequest permutations all happen on the same thread, or you'll likely run into these silent failures.