如何通过ShareKit在Facebook上发布带有图像的URL

jus*_*nny 10 iphone url facebook image sharekit

我在我的iPhone应用程序中使用sharekit在Facebook上分享网址链接.但是,在我看来,不可能与sharekit共享图像的URL.你们知道怎么做吗?非常感谢.

Akb*_*han 11

请查看我在SHKFacebook.m/h文件中创建自己的Send方法的代码,我认为它会对您有所帮助.

  -(BOOL) sendWithImage :(NSString*)creativeUrl 
   {
            self.pendingFacebookAction = SHKFacebookPendingStatus;

        SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease];
        dialog.delegate = self;
        dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:");
        dialog.attachment = [NSString stringWithFormat:
                             @"{\
                             \"name\":\"%@\",\
                             \"href\":\"%@\",\
                             \"media\":[{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"}]\
                             }",
                            item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title),
                            SHKEncodeURL(item.URL),
                            creativeUrl,
                            SHKEncodeURL(item.URL) 

                        ];
    dialog.defaultStatus = item.text;
    dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]",
                            SHKEncode(SHKMyAppName),
                            SHKEncode(SHKMyAppURL)];
    [dialog show];
    return YES; 

}
Run Code Online (Sandbox Code Playgroud)

这是我如何使用它

SHKFacebook *fb =[[SHKFacebook alloc]init];

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@iphone/photo?id=%d",[SplashViewController getBaseURL],[photoId intValue]]];
    fb.item = [SHKItem URL:url title:[dicResult valueForKey:@"Caption"]];
    //fb.shareType = SHKShareTypeURL;
    fb.quiet = YES;
    [TedryUITabBarController updateProgress:10 totalByteToSent:11 message:@"Sharing on facebook"];
    [fb sendWithImage:[dicResult valueForKey:@"CreativeURL"] :@""]; 
Run Code Online (Sandbox Code Playgroud)


Gav*_*vin 5

对于那些在这里遇到其他答案问题的人(虽然原则上基本相同),这可能会稍微简单一点.

将自定义值添加到项目中,例如:

[item setCustomValue:@"Your caption" forKey:@"caption"];
[item setCustomValue:@"Your description" forKey:@"description"];
[item setCustomValue:@"Your image URL" forKey:@"mediaSrc"];
[item setCustomValue:@"Your image link" forKey:@"mediaHREF"];
Run Code Online (Sandbox Code Playgroud)

请注意底部图像所需的两个值:源URL和链接URL.然后,您需要修改SHKFacebook.m中的"send"方法以使用这些值,如下所示:

// ...
if (item.shareType == SHKShareTypeURL)
{
    self.pendingFacebookAction = SHKFacebookPendingStatus;

    SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease];
    dialog.delegate = self;
    dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:");

    // with image...
    dialog.attachment = [NSString stringWithFormat:
                         @"{\
                         \"name\":\"%@\",\
                         \"href\":\"%@\",\
                         \"caption\":\"%@\",\
                         \"description\":\"%@\",\
                         \"media\":[\
                            {\
                                \"type\": \"image\",\
                                \"src\": \"%@\",\
                                \"href\": \"%@\"\
                            }]\
                         }",
                         item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title),
                         SHKEncodeURL(item.URL),
                         [item customValueForKey:@"caption"],
                         [item customValueForKey:@"description"],
                         [item customValueForKey:@"mediaSrc"],
                         [item customValueForKey:@"mediaHREF"]
                         ];

    dialog.defaultStatus = item.text;
    dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]",
                          SHKEncode(SHKMyAppName),
                          SHKEncode(SHKMyAppURL)];
    [dialog show];

}
// ...
Run Code Online (Sandbox Code Playgroud)

而jumponadoughnut给出的链接你可以使用的最终字段列表(我无法投票,因为我的代表不够高):http://developers.facebook.com/docs/guides/attachments


jum*_*nut 3

您需要在 [SHKFacebook send:] 实现中找到的附件 json NSString 中包含媒体 url。请参阅http://developers.facebook.com/docs/guides/attachments