iPhoneアプリでシェアキットを使用して、FacebookでURLリンクを共有しています。ただし、シェアキットで画像付きのURLを共有することはできないようです。皆さんはそれを行う方法を知っていますか?どうもありがとう。
4 に答える
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;
}
これが私がそれを使用する方法です
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"] :@""];
ここで他の回答に問題がある人にとっては、これは少し簡単かもしれません(基本的には同じですが)。
次のようなカスタム値をアイテムに追加します。
[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"];
下部の画像に必要な 2 つの値 (ソース 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];
}
// ...
そして、jumponadoughnut によって提供されたリンクは、使用できるフィールドの決定的なリストです (担当者が十分に高くないため、彼に投票できませんでした): http://developers.facebook.com/docs/guides/attachments
githubの最新のシェアキットを使用しています。実際には、キー「picture」を使用して、URLをリンクのカスタム値として設定するだけです。
NSString *urlImage = @"http://someurl.com/someimage.jpg";
[linkItem setCustomValue:urlImage forKey:@"picture"];
わたしにはできる。
[SHKFacebook send:]実装にある添付ファイルjsonNSStringにメディアURLを含める必要があります。http://developers.facebook.com/docs/guides/attachmentsを参照してください