I am using fb-messenger://compose to open Facebook Messenger Composer, but I can't manage to put predefined message into the composer.
Does somebody know the parameters?
You should send content via messenger using FBSDKShareKit.
Import FBSDKShareKit
#import <FBSDKShareKit.h>
Create content and share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.url.com"];
content.contentTitle = #"My link!";
content.contentDescription = #"Check out my link!";
[FBSDKMessageDialog showWithContent:content delegate:self];
You also need to conform your controller to the FBSDKSharingDelegate
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}
Available contents are:
FBSDKShareLinkContent
FBSDKSharePhotoContent
FBSDKShareVideoContent
Related
I am trying to open Facebook Messenger to send a message from my iOS app. I am currently running FaceBook SDK version 4.37.0. According to iOS - Sharing, this should be possible. It says
People can also share content from your app to Facebook Messenger with Messenger Expression Platform or from Sharing's Message Dialog in iOS SDK.
If you click on the link for Message Dialog, it provides you with the following example:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:myFacebookURL];
content.quote = #"My message";
[FBSDKMessageDialog showWithContent:content delegate:self];
I have implemented this as well as the FBSDKSharingDelegate delegate methods of:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"complete");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"Sharer Error");
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"Cancelled");
}
The delegate methods never get called. What I would expect is that a Facebook Messenger dialog would open allowing me to select a friend to message. But nothing opens. And there are no errors being logged.
I do know that facebook is receiving something because I get the following:
FBSDKLog: param {
"advertiser_id" = "xxxxxxxxx";
"advertiser_tracking_enabled" = 1;
"anon_id" = "xxxxxxxx";
"application_
tracking_enabled" = 1;
"custom_events" = "[{\"_eventName\":\"fb_mobile_content_view\",\"_logTime\":1541721304,\"fb_description\":\"MY FEATURE Sent\",\"_ui\":\"no_ui\"},{\"_ui\":\"no_ui\",\"_eventName\":\"fb_messenger_dialog_share_show\",\"_logTime\":1541721310,\"_implicitlyLogged\":\"1\",\"fb_dialog_share_content_type\":\"Status\"}]";
event = "CUSTOM_APP_EVENTS";
extinfo = "[\"i2\",\"com.myApp\",\"1\",\"8.3.6\",\"12.0.1\",\"iPhone10,6\",\"en_US\",\"CST\",\"AT&T\",375,812,\"3.00\",6,60,8,\"America\\/Chicago\"]";
"url_schemes" = "[\"myappID\",\"myscheme1\",\"myscheme2\",\"myscheme3\"]";
}
Any help or pointers would be appreciated.
FBSDKMessageDialog.show(with: FBSDKShareLinkContent(), delegate: nil)
I have the same issue but experimentally I only pass FBSDKShareLinkContent() as a content param and messenger app start
You should also add fb-messenger-share-api key in Info.plist under LSApplicationQueriesSchemes
I am trying to send app invitation to facebook friends but getting the following error
app invite error:Error Domain=com.facebook.sdk.core Code=9 "The operation couldn’t be completed. (com.facebook.sdk.core error 9.)"
below is my code
-(IBAction)buttonTapped:(id)sender {
FBSDKAppInviteContent *content = [[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://fb.me/115385318808986"];
[FBSDKAppInviteDialog showWithContent:content
delegate:self];
}
#pragma mark - FBSDKAppInviteDialogDelegate
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results
{
// Intentionally no-op.
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
NSLog(#"app invite error:%#", error);
NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?:
#"There was a problem sending the invite, please try again later.";
NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: #"Oops!";
[[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
and when I am trying to print the error.userInfo it shows a blank dictionary. Please guide.
For facebook sdk 4.0 and later
at first create an applink.
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://www.google.com/myapplink"];
//optionally set previewImageURL
content.appInvitePreviewImageURL = [NSURL URLWithString:#"https://www.google.com/my_invite_image.jpg"];
// present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate`
[FBSDKAppInviteDialog showWithContent:content
delegate:self];
see this link https://developers.facebook.com/docs/app-invites/ios
EDIT:
when you create an app link and you have to provide an url scheme,this url scheme added in your project info plist.after that you add a face book canvas platform in face book developer setting page,and provide a canvas url and save it.
If you've been looking everywhere like me to figure out why it's not working, turns out Facebook is deprecating App Invites and will completely stop working as of 2/6/2018:
https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/
I had this error as well. What fixed it was adding
[FBSDKAppEvents activateApp];
in applicationDidBecomeActive:(UIApplication *)application
within the appDelegate. See also https://developers.facebook.com/docs/app-events/ios#appActivation
I am trying to set up Facebook sharing with FBSDK in my iOS app.
I have been reading the documentation here, and currently have
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
working with a content object - FBSDKShareLinkContent.
However, upon trying to use the similar method as specified for Facebook Messenger sharing,
[FBSDKMessageDialog showWithContent:content delegate:self];
i am getting a crash. I caught the error and logged it in one of the delegate methods, and it states "The operation couldn’t be completed. (com.facebook.sdk.share error 202.)
"
I have searched for this specific error but have not found anything directly with the same error. Here is full code
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:kAPPShareLink];
content.contentDescription = kAPPShareDescription;
content.contentTitle = kAPPShareTitle;
if (buttonIndex == 0) {
// Facebook
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
} else if (buttonIndex == 1) {
// Facebook Messenger
[FBSDKMessageDialog showWithContent:content delegate:self];
}
Forgive me if i am missing something obvious, but as this documentation reads, i assume the FBSDKMessageDialog showWithContent: method would work the same way as FBSDKShareDialog showFromViewController: which is working for me.
I am using the latest version of XCode with iOS8.
I had to login and then Post , that is how it worked :
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:#[#"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://developers.facebook.com/"];
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
messageDialog.delegate = self;
[messageDialog setShareContent:content];
if ([messageDialog canShow])
{
[messageDialog show];
}
else
{
// Messenger isn't installed. Redirect the person to the App Store.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/en/app/facebook-messenger/id454638411?mt=8"]];
}
}
}];
and the Share Delegate :
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"didCompleteWithResults");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError ::: %#" , error);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"sharerDidCancel");
}
Edit:
[messageDialog canShow] returns NO on the iPad, works fine on iPhone
Posted the issue on Facebook Developers forum.
I was stuck with this for a while and in the end realised that I had not added fb-messenger-share-api under LSApplicationQueriesSchemes in the info.plist file. Just putting this here in case it helps someone. Thanks :)
N.B. It is fb-messenger-share-api and not fb-messenger-api.
Note: This fits more as a comment, but I don't have enough reputation yet to post comments
I get the same error, both Facebook and messenger are updated.
I checked my permissions with
[[FBSDKAccessToken currentAccessToken] permissions]
and I think I have enough:
"contact_email",
"publish_stream",
"user_likes",
"publish_checkins",
"video_upload",
"create_note",
"basic_info",
"publish_actions",
"public_profile",
"photo_upload",
"status_update",
email,
"user_friends",
"share_item"
I tried the same way as OP, and also I tried that:
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
[messageDialog setShareContent:content];
messageDialog.delegate = self;
if ([messageDialog canShow]) {
[messageDialog show];
}
[messageDialog canShow] returns NO, and the delegate methods catch the fail with the 202 error described by the OP.
I tried using the FBSDKSendButton, and doesn't seem to work either.
On the other hand, FBSDKShareDialog works perfectly...
I hope this helps to solve the issue.
This bubbled up again in an interweb search. Nowadays, there is a simple answer for the error Message dialog is not available with code 202:
Facebook's documentation:
Note: Currently the message dialog is not supported on iPads.
I was integrating twitter in my app. I googled and searched in stack, could not find proper steps.
Can anyone tell me how it works in detail.
Thank You.
I Hope This will help you . . .
1.Add following classes to your project
GTMOAuthAuthentication.h/m
GTMOAuthSignIn.h/m
GTMHTTPFetcher.h/m
GTMOAuthViewControllerTouch.h/m
GTMOAuthViewTouch.xib
2 . Add following frameworks
Security.framework and SystemConfiguration.framework.
3 .set -ObjC build option for the application target's "Other Linker Flags".
4 . Then it's time for some coding .
import GTMOAuthAuthentication.h and GTMOAuthViewControllerTouch.h
- (void)signInWithTwitter
{
NSURL *requestURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/authorize"];
NSString *scope = #"http://api.twitter.com/";
GTMOAuthAuthentication *auth = [self authForTwitter];
[auth setCallback:#"http://www.noop.com/OAuthCallback"];
GTMOAuthViewControllerTouch *viewController;
viewController = [[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
requestTokenURL:requestURL
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:#"AppName : Twitter"
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
[appDelegate.navigationController pushViewController:viewController animated:YES];
}
- (GTMOAuthAuthentication *)authForTwitter {
GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
consumerKey:TWITTER_CONSUMER_KEY
privateKey:TWITTER_CONSUMER_SECRET];
[auth setServiceProvider:#"Twitter"];
return auth;
}
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController finishedWithAuth:(GTMOAuthAuthentication *)auth error:(NSError *)error {
if(error)
{
//handle error
}
else
{
// do stuff as per your app.
}
}
NOte : if you get error message like "failed to validate oauth signature and token" then check you system time is correct or not .
1) Download oauth Library for authotication for ios.
2) Create Account on Twitter with all Keys
Consumer Key ,Consumer Secrete,access key access token
Add int into ....
3) -(void)getList{
OAConsumer *con = [[OAConsumer alloc]initWithKey:#"TwitterConsumerKey" secret:#"TwitterConsumerSecret"];
OAToken *p=[[OAToken alloc]initWithKey:[#"TwitterAccessTokenKey" secret:#"TwitterAccessTokenSecret"];
int kPageCount=10;
NSString* pro=[NSString stringWithFormat:#"%#count=%i", #"https://api.twitter.com/1.1/statuses/user_timeline.json?",kPageCount];
NSURL *tt=[NSURL URLWithString:pro];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:tt
consumer:con
token:p
realm:nil
signatureProvider:nil] ;
[request setHTTPMethod:#"GET"];
fetcher = [[OADataFetcher alloc] init] ;
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:#selector(requestTokenTicket:didFinishWithData:)
didFailSelector:#selector(requestTokenTicket:didFailWithError:)];
}
}
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *)err {
if (err.domain==NSURLErrorDomain && err.code==-1001) {
[self getList];
}
}
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
NSString *responseBody = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(#"responseBody :%#",responseBody);
}
For an app I'm working on I'm integrating different social services the user can select to share the content created using the app.
What I'm trying to understand is if the facebook-messenger app expose an URL scheme that can be used to perform some action (basically texting one of his/her friend), or if there is a specific UTI that can be used in conjunction with the UIDocumentInteractionController.
Thanks in advance for any help / hint / suggestion
You cannot compose message but you can send a link, photo or video via messenger.
Facebook provides API for that.
Import FBSDKShareKit
#import <FBSDKShareKit.h>
Create content and share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.url.com"];
content.contentTitle = #"My link!";
content.contentDescription = #"Check out my link!";
[FBSDKMessageDialog showWithContent:content delegate:self];
You also need to conform your controller to the FBSDKSharingDelegate
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}
Available contents are:
FBSDKShareLinkContent
FBSDKSharePhotoContent
FBSDKShareVideoContent
Facebook Messenger URL scheme on iOS is fb-messenger://, I don't know if it's possible to open a composer that will let you choose contacts or pre fill it with a message.
You can open a conversation if you know the Facebook user ID: fb-messenger://user-thread/[facebook-user-id]