Aditya
Aditya

Reputation: 823

Facebook Messenger SDK to share text and url to facebook friends

I m trying to send text message which also contains urls to my friends on fb messenger, but not getting any way to send them.

I have tried this

 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.")
    }

but this is only for sharing links

I tried sending message using urlscheme also but it just opens up the 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 ")
    }

In android it is possible by this

    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");
   }

This is sent from android

This is sent from android

Any help will be appreciated

Thanks in advance

Upvotes: 0

Views: 4447

Answers (2)

Daniel Popov
Daniel Popov

Reputation: 171

Same as Виктор Иванов answer in 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 are now deprecated

Upvotes: 4

Try this:

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

Upvotes: 2

Related Questions