2011-02-03 18 views
0

私はFacebookに文字列メッセージを投稿しようとしていますが、添付ファイルの文字列ではなく、ユーザーがメッセージの種類を投稿します。どうしたらいいですか? JSONFragment方法は、単に私は、これはあなたを助けることを願っ同等のJSON形式Facebookに添付ファイル付きメッセージを投稿するには?

- (NSString *)JSONFragment { 
    SBJsonWriter *jsonWriter = [SBJsonWriter new]; 
    NSString *json = [jsonWriter stringWithFragment:self];  
    if (!json) 
     NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]); 
    [jsonWriter release]; 
    return json; 
} 

に添付ファイルを変換し

- (void)postToWall { 

FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease]; 
dialog.delegate = self; 
NSString *joke = @"Hello i am happy"; 
dialog.userMessagePrompt = @"Enter your message:"; 

dialog.attachment = [NSString stringWithFormat:@"{\"name\":,\"%@ Posted Message!}", 
        facebookName, joke]; 

[dialog show]; 

}

答えて

1
NSString *customMessage = [NSString stringWithFormat:@"CUSTOM MESSAGE"]; 
NSString *postName = @"SAMPLE_APP"; 
NSString *serverLink = [NSString stringWithFormat:@"http://www.google.co.in "]; 
NSString *imageSrc = @"PATH OR URL TO IMAGE"; 

NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] init]autorelease]; 
[dictionary setObject:postName forKey:@"name"]; 
[dictionary setObject:serverLink forKey:@"href"]; 
[dictionary setObject:customMessage forKey:@"description"]; 

NSMutableDictionary *media = [[[NSMutableDictionary alloc] init]autorelease]; 
[media setObject:@"image" forKey:@"type"]; 
[media setObject:serverLink forKey:@"href"]; 
[media setObject:imageSrc forKey:@"src"];    
[dictionary setObject:[NSArray arrayWithObject:media] forKey:@"media"];   

FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease]; 
dialog.delegate = self; 
dialog.userMessagePrompt = @"Share with All"; 
dialog.attachment = [dictionary JSONFragment]; 
[dialog show]; 

関連する問題