Reputation: 882
I have to send app request using facebook sdk as it was not possible through graph call. I have already got my facebook token as well as SLRequest object with access permission granted(yes). I just want to create fb session using above two parameters so that user does not have to enter his credentials on the pop up and the credentials will be automatically taken from SLrequest or Accounts object or from access token.
Upvotes: 0
Views: 303
Reputation: 882
Finally got the solution, call the requestGrantedForFb just after you get your request granted from account store :
-(void)requestGrantedForFb
{
if (gblAppDelegate.session.isOpen)
{
[self SendReqClk];
} else
{
if (gblAppDelegate.session.state != FBSessionStateCreated)
{
gblAppDelegate.session = [[FBSession alloc] init];
}
NSArray *permissionArray = [NSArray arrayWithObjects:@"read_friendlists",@"basic_info",nil];
dispatch_async(dispatch_get_main_queue(), ^{
[FBSession openActiveSessionWithReadPermissions:permissionArray
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (session.isOpen)
{
gblAppDelegate.session = session;
[self SendReqClk];
} else
{
gblAppDelegate.session = session;
}
}];
});
}
}
After that
-(void)SendReqClk
{
NSError *error;
NSData *jsonData = [NSJSONSerialization
dataWithJSONObject:@{
@"social_karma": @"5",
@"badge_of_awesomeness": @"1"}
options:0
error:&error];
if (!jsonData) {
NSLog(@"JSON error: %@", error);
return;
}
NSString *giftStr = [[NSString alloc]
initWithData:jsonData
encoding:NSUTF8StringEncoding];
NSMutableDictionary* params = [@{@"data" : giftStr} mutableCopy];
// Display the requests dialog
dispatch_async(dispatch_get_main_queue(), ^{
[FBWebDialogs
presentRequestsDialogModallyWithSession:gblAppDelegate.session
message:@"Welcome to !!! "
title:@"Join now !!!"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(@"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(@"User canceled request.");
[self.navigationController popViewControllerAnimated:YES];
} else {
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"]) {
// User clicked the Cancel button
NSLog(@"User canceled request.");
[self.navigationController popViewControllerAnimated:YES];
} else if(result== FBWebDialogResultDialogCompleted){
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:@"request"];
UIAlertView *aAlertSuccess=[[UIAlertView alloc]initWithTitle:@"" message:@"Friend request sent successfully!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[aAlertSuccess show];
NSLog(@"Request ID: %@", requestID);
// [NSThread detachNewThreadSelector:@selector(stopActivity) toTarget:self withObject:nil];
// UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"my alert" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];//
// [alert setTag:125];
// [alert show];
}
}
}
}];
});
}
Upvotes: 1