2011-01-14 161 views

回答

11

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

-(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; 

} 

这里是我如何使用它

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"] :@""]; 
+1

好的回复,非常有帮助 – justicepenny 2011-02-21 09:45:01

+0

scompt,你能帮我开始你的代码吗?该项目在哪里?我以为sharekit是关于这个项目的......我怎么称呼sendWithImage - 你能展示一个样本吗?谢谢! – 2011-04-21 08:45:47

+0

你错过了你的代码大块,所以它是不可能工作你已经解决了它 – daidai 2011-09-29 13:05:06

4

我使用的是从GitHub最新sharekit。其实,你只需将网址设置为链接的自定义值,使用关键“图片”

NSString *urlImage = @"http://someurl.com/someimage.jpg"; 
[linkItem setCustomValue:urlImage forKey:@"picture"]; 

它适用于我。

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"]; 

注意需要在底部的图像的两个值。然后,您需要修改SHKFacebook.m“发送”的方法来使用这些值,如下所示:

// ... 
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]; 

} 
// ... 

而且通过jumponadoughnut 给出的链接是字段定义列表,你可以使用(我做不到投票他,因为我的代表不够高):http://developers.facebook.com/docs/guides/attachments

相关问题