在iOS中使用SLRequest的Facebook会话
我必须使用facebook sdk发送应用程序请求,因为这不可能通过图形调用实现。我已经获得了我的facebook令牌和SLRequest对象,并授予了访问权限(是)。我只想使用以上两个参数创建fb会话,这样用户就不必在弹出窗口中输入凭据,凭据将自动从SLrequest或Accounts对象或access token中获取。最终获得了解决方案,在您从帐户存储获得请求许可后,立即致电requestGrantedForFb:在iOS中使用SLRequest的Facebook会话,ios,facebook-graph-api,slrequest,facebook-sdk-3.1,acaccountstore,Ios,Facebook Graph Api,Slrequest,Facebook Sdk 3.1,Acaccountstore,我必须使用facebook sdk发送应用程序请求,因为这不可能通过图形调用实现。我已经获得了我的facebook令牌和SLRequest对象,并授予了访问权限(是)。我只想使用以上两个参数创建fb会话,这样用户就不必在弹出窗口中输入凭据,凭据将自动从SLrequest或Accounts对象或access token中获取。最终获得了解决方案,在您从帐户存储获得请求许可后,立即致电requestGrantedForFb: -(void)requestGrantedForFb { if (gbl
-(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;
}
}];
});
}
}
之后
-(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];
}
}
}
}];
});
}
我也有同样的问题。您对此有什么解决方案吗?@sahara108是的,我终于找到了解决方案,请阅读答案。谢谢分享。我也找到了这个解决方案。但我只是做
[FBSession setActiveSession:session]代码>在回调中。从现在起,我可以正常使用FB Sdk:P