ごらくらいふ

プログラミングしたりゲームしたり

FacebookSDK 3.x -> 4.x : FBRequestConnection startWithGraphPath:completionHandler:が無くなったので FBSDKGraphRequest startWithCompletionHandler:を使う

記事タイトルキャメルケースでキッツキツだな。

結論

3.xにてGraphAPIを手軽に叩くため、FBRequestConnection startWithGraphPath:completionHandler:を使っていた。

4.xでは失くなってしまったのでFBSDKGraphRequest startWithCompletionHandler:を使った。

コードで見る違い

3.x

- (void) callGraphApi:(NSString*)graphPath {
    [FBRequestConnection startWithGraphPath:graphPath completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    }];
}

4.x

- (void) callGraphApi:(NSString*)graphPath {
    // 一個一個変数化するとデバッグしやすくて好き
    FBSDKGraphRequest* fbRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:nil];
    [fbRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    }];
}

「なんでじゃ」と思ったこと集

  • FBRequestConnectionでやってたことがFBSDKGraphRequestConnectionではなくFBSDKGraphRequestに納まっていたこと
  • FBSDKGraphRequest startWithCompletionHandler:のコールバック、FBSDKGraphRequestHandlerの定義がFBSDKGraphRequestConnectionにあったこと
  • よくみるとFBSDKGraphRequestConnectionFBSDKGraphRequestをimportしておらず、その逆だったこと
    • 依存の仕方が直感に沿わない…内部クラスかしら?って思った