【问题标题】:can change facebook app invitation text using graph api可以使用图形 api 更改 facebook 应用程序邀请文本
【发布时间】:2013-04-30 14:04:49
【问题描述】:

我们可以使用 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];   

}

【问题讨论】:

    标签: ios objective-c facebook facebook-graph-api


    【解决方案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];
    

    【讨论】:

    • 感谢 jai govindani 的帮助 .. :) 但是任何关于 Graph api 的想法都会更有帮助,因为我的应用程序快完成了,这次我无法更改 fb sdk。
    • 所以您使用的是 3.x 之前的 SDK 版本?
    • 我使用了这个链接中的课程:- github.com/megastep/facebook-iphone-sdk/blob/master/src/…
    • 您能否发布您当前用于发送应用请求的代码,以便我对其进行修改,而不是发布您可能因 SDK 版本而无法使用的内容?
    • 查看最新编辑,使用 FBDialog。但是请注意,FBDialog 不是直接调用的,而是通过 Facebook 对象按照 FB 在 FBDialog.h 中的说明使用的
    猜你喜欢
    • 1970-01-01
    • 2015-09-29
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2013-02-26
    • 1970-01-01
    相关资源
    最近更新 更多