4

今までFacebookリクエストを送信できないこのコードがあります。

NSDictionary *firstDict = [NSDictionary dictionaryWithObjectsAndKeys:
    @"image", @"Type",
    @"http://mysite.com/image.jpg", @"src",
    @"http://mysite.com/page.html", @"href",
    nil];
NSDictionary *secondDict = [NSDictionary dictionaryWithObjectsAndKeys:
    @"image", @"Type",
    @"http://mysite.com/image.jpg", @"src",
    @"http://mysite.com/page.html", @"href",
    nil];
NSArray *mediaArray = [[NSArray alloc] initWithObjects:firstDict, secondDict, nil];

NSArray *keys = [NSArray arrayWithObjects:@"name", @"description", @"href", @"media", nil];
NSArray *objects = [NSArray arrayWithObjects:
    [NSString stringWithString:@"MyTitle"],
    [NSString stringWithString:@"My caption"],
    [NSString stringWithString:@"http://mysite.com/page.html"], mediaArray, nil];

NSDictionary *attachment = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
[[FBRequest requestWithDelegate:self] call:@"facebook.stream.publish" params:attachment];

私はこのサンプルを取りました: http://forum.developers.facebook.com/viewtopic.php?pid=145965

しかし、実行するたびに、コンソールに次のように表示されます。

 {
     "api_key" = adc8d70987098sdc;
     "call_id" = 23456767;
     description = "Any user's description";
     format = XML;
     href = "http://mysite.com/page.html";
     media =     (
                 {
             Type = image;
             href = "http://mysite.com/page.html";
             src = "http://mysite.com/image.jpg";
         },
                 {
             Type = image;
             href = "http://mysite.com/page.html";
             src = "http://mysite.com/image.jpg";
         }
     );
     method = "Facebook.streamPublish";
     name = aName;
     "session_key" = "d0f98bfs89b7fg7v";
     sig = 89v0d9fv879fgv;
     ss = 1;
     v = "1.0"; }

括弧の代わりに配列の括弧が表示されますが、それは正常ですか?.

次に、エラーが表示されます。

*** -[NSCFArray dataUsingEncoding:]: unrecognized selector sent to instance
     0x12fcb0 2009-10-30 13:54:27.758 GeoPixr[307:207]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
*** -[NSCFArray dataUsingEncoding:]: unrecognized selector sent to instance 0x12fcb0

[セッション再開] 呼び出しは TRUE を返します。

前もって感謝します。

4

4 に答える 4

13

最新のiOS SDK For Facebookを使用している場合は、以下の方法を使用して画像をストリームとして公開できます。

- (IBAction) publishStream: (id)sender {

  SBJSON *jsonWriter = [[SBJSON new] autorelease];

  NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                               @"Always Running",@"text",@"http://thinkdiff.net",@"href", nil], nil];

  NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
  NSDictionary* imageShare = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"画像", @"タイプ",
                                @"http://thinkdiff.net/mahmud_small.jpg", @"src",
                                @"http://thinkdiff.net", @"href",
                                なし];

  NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                               @"長い目", @"名前",
                               @"Facebook ランニング アプリ", @"キャプション",
                               @「楽しい」、@「説明」、
                               @"http://itsti.me/", @"href",
                               [NSArray arrayWithObjects:imageShare, nil ], @"media",
                              なし];
  NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
    NSLog(attachmentStr);
  NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 kAppId、@"api_key"、
                                 @"Facebook で共有", @"user_message_prompt",
                                 actionLinksStr, @"action_links",
                                 attachmentStr, @"添付ファイル",
                                 なし];

  [_facebook ダイアログ: @"stream.publish"
          andParams: パラメータ
        andDelegate:self];
}

画像部分は別の NSDictionary オブジェクトにする必要があります。

NSDictionary* imageShare = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"画像", @"タイプ",
                                @"http://thinkdiff.net/mahmud_small.jpg", @"src",
                                @"http://thinkdiff.net", @"href",
                                なし];

添付ファイルの NSDictionary オブジェクトには、imageShare オブジェクトを配列として含める必要があります

[NSArray arrayWithObjects:imageShare, nil ]

これは、これを配列として含めないと、Json パーサーが [] ブラケットを回避するため、発行機能が機能しないためです。文字列は有効な JSON 文字列である必要があることに注意してください。そうでない場合、facebook API は公開されません。

于 2010-08-23T18:32:25.967 に答える
1

辞書を配列で送信する方法が見つかりませんでしたが、別のクラスがあります。

FBStreamDialog

情報を送信する前にダイアログが表示され、デリゲート メソッドによって変更が通知されます。

于 2009-11-06T22:39:48.297 に答える
0

あなたの例を少し修正しましたが、うまくいきます。作業コードは次のとおりです。

NSString *att = @"{\"name\":\"i\'m bursting with joy\",\"caption\": \"User rated the lolcat 5 stars\", \"description\": \"a funny looking cat\"}";
NSDictionary *attachment = [NSDictionary dictionaryWithObject:att forKey:@"attachment"];
[[FBRequest requestWithDelegate:self] call:@"facebook.stream.publish" params:attachment];
于 2010-01-26T22:44:17.480 に答える
0

dataUsingEncoding:はメソッドであるため、おそらく、一部のオブジェクトは、配列を渡した場所NSStringのインスタンスを期待しています。NSStringあなたがディクショナリに含めた配列を FBRequest が処理できないと思いますattachment

于 2009-10-30T21:20:07.093 に答える