3

我们可以使用 facebook Graph api 更改 facebook 应用程序邀请文本吗?

一般有格式——“邀请人姓名给你发了请求”,我们可以把这个文本替换成我们自己的吗?

(这会在 fb 墙上显示为通知。)

我正在使用下面的代码 -

- (void)load:(BOOL)NeedToSendAppRequest AndMessage:(NSString*)message AndFriendID:(NSString*)friendID {

    NSString *urlString = nil;
    isNeedToSendAppRequest = NeedToSendAppRequest;

    if (NeedToSendAppRequest) {
        NSString *redirectUrlString = FACEBOOK_REDIRECT_URL;
        NSString *authFormatString = @"https://m.facebook.com/dialog/apprequests?app_id=%@&target_url=fb%@&to=%@&message=%@&redirect_uri=%@";
        urlString = [NSString stringWithFormat:authFormatString, _apiKey, _apiKey,friendID,message,redirectUrlString];  
    }else{
        NSString *redirectUrlString = @"http://www.facebook.com/connect/login_success.html";
        NSString *authFormatString = @"https://graph.facebook.com/oauth/authorize?client_id=%@&redirect_uri=%@&scope=%@&type=user_agent&display=touch";
        urlString = [NSString stringWithFormat:authFormatString, _apiKey, redirectUrlString, _requestedPermissions];
    }

   NSURL *url = [NSURL URLWithString:urlString];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];
   [_webView loadRequest:request];   

}
4

1 回答 1

-1

查看下面的示例 -friendToInviteCSVString是您要邀请的朋友 FB ID 的逗号分隔字符串。message您可以在参数字典的键中设置自定义邀请消息。

顺便说一下,这是使用 3.x FB iOS SDK:

 //Remove last comma from CSV string
 friendToInviteCSVString = [friendToInviteCSVString stringByTrimmingCharactersInSet:[NSCharacterSet punctuationCharacterSet]];

 NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           NSLocalizedString(@"Check out this awesome app.", @"Check out this awesome app."), @"message",
                                           friendToInviteCSVString, @"to", nil];



//Do FB invites
DDLogVerbose(@"Active fb session: %@", [FBSession activeSession]);

[FBWebDialogs presentDialogModallyWithSession:[FBSession activeSession] dialog:@"apprequests" parameters:parameters handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
 {
      DDLogVerbose(@"Facebook closed dialog with result: %d, URL: %@, error: %@", result, resultURL, error);
 }];

编辑:

好的,所以我在我的遗留代码中进行了挖掘,这是一个使用 FBDialog 的示例,它是您正在使用的 SDK 版本中可用的。首先你需要一个Facebook对象:

Facebook *facebook = [[Facebook alloc] initWithAppId:kFBAppID andDelegate:self];

 //Check if token is valid
if (FBSession.activeSession.accessToken)
{
    DLog(@"Init FB with activeSession, token: %@ and expirationDate: %@", FBSession.activeSession.accessToken, FBSession.activeSession.expirationDate);

    self.facebook.accessToken = FBSession.activeSession.accessToken;
    self.facebook.expirationDate = FBSession.activeSession.expirationDate;
}
else
{
    //No FB Token, do something here - ask user for permission, etc
}

NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   NSLocalizedString(@"Check out this awesome app.", @"Facebook apprequest invite message"), @"message", friendsToInvite, @"to", nil];

 [self.facebook dialog:@"apprequests" andParams:parameters andDelegate:self];
于 2013-04-30T14:49:36.553 回答