FB 图订阅 IOS 发送 access_token

FB Graph Subscription IOS send access_token

Facebook Graph SDK(及其 iOS 实现)确实让我的生活很痛苦。看来我只能靠自己了,因为我似乎无法在网络上找到像我这样有类似 problem/lack 理解力的人。

事不宜迟:

我的 iOS 应用程序中有这段代码,应该可以让我的应用程序订阅用户更新:

-(void)subscribeToFacebook{
    (FBSession.activeSession.isOpen) ? NSLog(@"is open") : NSLog(@"is closed");

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"page", @"object",
                            @"http://www.example.com/fbcallback.php", @"callback_url",
                            @"about, picture", @"fields",
                            @"ItsMeAlright", @"verify_token",
                            nil
                            ];
    /* make the API call */
    [FBRequestConnection startWithGraphPath:@"/app/subscriptions"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(
                                              FBRequestConnection *connection,
                                              id result,
                                              NSError *error
                                              ) {
                              /* handle the result */
                               NSLog(@"error= %@",error);
                          }];
    }

当我 运行 此代码时,记录了一个错误,指出:

"(#15) This method must be called with an app access_token."

现在,我(认为)我知道如何获得 access_token

 NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];

但我不知道何时何地发送到 Facebook。

我试过像这样将它附加到 @"/app/subscriptions" 部分

NSString *urlString = [NSString
                           stringWithFormat:@"/app/subscriptions?access_token=%@",
                           [fbAccessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

但这没有用。

非常欢迎您的意见!

执行此操作的方法是使用应用程序令牌创建 FBSession。因为当前会话不是你想要的。

但是,出于安全考虑,您根本不应该这样做。将您的应用程序令牌嵌入到生产应用程序中是非常不安全的。我认为为您生成的 iOS 样本不正确。

您应该通过服务器调用发送任何需要应用程序令牌的请求(例如 PHP)