[英]Is there a way to share text on facebook messenger without SDK?
[英]Facebook Messenger SDK to share text and url to facebook friends
我正在尝试向fb Messenger上的朋友发送包含URL的文本消息,但没有任何发送方法。
我已经试过了
let result = FBSDKMessengerSharer.messengerPlatformCapabilities().rawValue & FBSDKMessengerPlatformCapability.Image.rawValue
if result != 0 {
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: Urls().WEONE_ITUNES_TINYURL)
content.contentDescription = "Dscription"
content.contentTitle = "Title"
let facebookSendButton: FBSDKSendButton = FBSDKSendButton()
facebookSendButton.shareContent = content
facebookSendButton.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
} else {
Utils().alertView(self, title: "Cannot Send Message", message: "Your device is not able to send Facebook Messenger messages.")
}
但这仅用于共享链接
我也尝试使用urlscheme发送消息,但它只是打开了fb Messenger:
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb-messenger-api://")!) {
var msgString = "Hello World: https://randomurl.com"
let urlStringEncoded = msgString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
var urlString = "fb-messenger://messaging?text=\(urlStringEncoded!)"
UIApplication.sharedApplication().openURL(NSURL(string: urlString)!)
}
else {
print("Failed to open fb-messenger App ")
}
在Android中,这是可能的
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Your message");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.show(this, "Please Install Facebook Messenger");
}
这是从android发送的
任何帮助将不胜感激
提前致谢
与Swift中的ВикторИванов答案相同:
let content = FBSDKShareLinkContent()
content.quote = "A nice quote here..."
content.contentURL = URL(string: "Your_Link")
let messageDialog = FBSDKMessageDialog()
messageDialog.delegate = nil
messageDialog.shareContent = content
if messageDialog.canShow() {
messageDialog.show()
}
现在不推荐使用.imageURL,.contentTitle和.contentDescription
尝试这个:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"YOUR_LINK"];
content.imageURL = [NSURL URLWithString:@"SOME_IMAGE"];
content.contentTitle = @"Awesome title here!";
content.contentDescription = @"Some description maybe...";
content.quote = @"A nice quote here...";
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
messageDialog.delegate = nil;
[messageDialog setShareContent:content];
if ([messageDialog canShow]) {
[messageDialog show];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.