How to share a post from my app to twitter iOS - ios

I basically want the user to share something from my app to twitter. I was exploring the different methods possible and found SLComposeViewController but it is deprecated. Support for twitterKit has also been officially stopped by twitter. One possible way to do so seems to be like given in the answers in this post. Is there some other better way to do so? I would prefer if the user stays in the app itself (something similar to sharesheet for fb). Thanks!

You can use twitter-kit-ios.
For posting a tweet sample code from documentation would be following
Objective-c
// Objective-C
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"just setting up my Twitter Kit"];
[composer setImage:[UIImage imageNamed:#"twitterkit"]];
// Called from a UIViewController
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) {
NSLog(#"Tweet composition cancelled");
}
else {
NSLog(#"Sending Tweet!");
}
}];
Swift
// Swift
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
// Called from a UIViewController
composer.show(from: self.navigationController!) { (result in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}
Straight from the discontinuing blog post you can use, new api endpoints.

Related

i am trying to share video to twitter from my iOS app but it keep asking login

- (void) share:(NSString*)filename {
BOOL status = [[TwitterVideoUpload instance] setVideo:filename];
if (status == FALSE) {
[self addText:#"Failed reading video file"];
return;
}
status = [[TwitterVideoUpload instance] upload:^(NSString* errorString)
{
NSString* printStr = [NSString stringWithFormat:#"Share video %#: %#", filename,(errorString == nil) ? #"Success" : errorString];
[self addText:printStr];
}];
if (status == FALSE) {
[self addText:#"No Twitter account. Please add twitter account to Settings app."];
}
}
this is my code, even after login into twitter in my simulator and browser it keep saying "Not logged in". Any solution?
According to the ReadMe document for the TwitterVideoUpload repo:
Twitter username + password must be provided to iOS Settings app
Logging in via Mobile Safari isn't going to do it.
You need to use iOS Settings to authenticate to Twitter.

Twitter and Facebook Sharing in iOS application using Social Framework in iOS 8.4 adding URL not working in Objective C

Adding URL in Twitter and Facebook sharing in iOS application using Social framework for iOS 8.4 is not working.
Only setInitialText: method is working but not the addURL and setTile methods.
My code is as follows:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbFeed = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbFeed setInitialText:self.travelogueTitle];
[fbFeed addURL:[NSURL URLWithString:self.saveTraveloguePublishedURL]];
[fbFeed setTitle:#"My Trip's Memories"];
NSLog(#"Save published url:%#",self.saveTraveloguePublishedURL);
NSLog(#"Share published url:%#",travelogue.publishedUrl);
// [fbFeed setInitialText:[NSString stringWithFormat:#"http://mvm064/MVPWeb/ViewTravelogue?travelogueId=OB1YlsTz/gngmCUTESuqlQ=="]];
[fbFeed setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"The user cancelled.");
}
else if (result == SLComposeViewControllerResultDone) {
NSLog(#"The user posted to Facebook");
}
}];
[self presentViewController:fbFeed animated:YES completion:nil];
}}
There is no method in SLComposeViewController to setTitle. SLComposeViewController is basically subclass of UIViewController so giving you facility to set title of SLComposeViewController. It will not going to post on Facebook. For post on Facebook you have method called setInitialText.
I have tried with your code and its get uploaded successfully, you can check out in following image.

SLComposeViewController post both image and url ios9

What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9
UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addURL:[NSURL URLWithString:str]];
[fbSheet addImage:tableViewScreenshot];
The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device.
And this one is when the Facebook app is not installed on the device
And this is my code:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addURL:[NSURL URLWithString:#"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"icon_circle"]];
[controller setInitialText:#"Bhavuk you're great!"];
[self presentViewController:controller animated:YES completion:nil];
So If you want to share everything, better use FB SDK.
So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.
Unfortunately, the problem remains even on iOS 10. An easy workaround is simply drop the URL, for example:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addImage:tableViewScreenshot];
It's not a direct answer to the OP but in case of what you only care is showing text and image while sharing something, here is a possible solution:
If the image and the text that you want to show within your SlComposeView is the same as the information that exist within the web site that you are going to share; you don't need to do anything special at the iOS side at all.
If you are the one who also created the web page that you're sharing URL of, should you have proper Open Graph META Tags at the page, SLComposeView of type Facebook will show image and text which were set at the webpage within your app automagically.
For some information about Facebook Open Graph Markup; see https://developers.facebook.com/docs/sharing/webmasters/#markup
I have had facebook sharing working fine in my ios app when fb not install. and i have installed fb to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NIDINFO(#"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(#"Facebook sharing getting publish_actions permission failed: %#", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: #{
#"og:type": #"article",
#"og:title": #"Bloc",
#"og:description": message,
#"og:url": #"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"mynamespace:Share" object:object key:#"article"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(#"Facebook sharing content failed: %#", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(#"Facebook sharing completed: %#", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(#"Facebook sharing failed: %#", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(#"Facebook sharing cancelled.");
}

Twitter SDK IOS : Compose using native Twitter App?

I've integrated Fabric Framework in my project, now i want to compose my image by using Twitter App installed from App Store, but twitter use SLComposeViewController UI of iOS, so i don't know what is different between using SLComposeViewController and Twitter SDK ?.
When i use Facebook SDK, sharing will use facebook app, with Twitter it not.
I use this code to compose Image.
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"just setting up my Fabric"];
[composer setImage:[UIImage imageNamed:#"fabric"]];
[composer showWithCompletion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) {
NSLog(#"Tweet composition cancelled");
}
else {
NSLog(#"Sending Tweet!");
}
}];

SoundCloud SDK on Swift, can't translate

I need to use SoundCloud SDK into a Swift. Does someone have experience in this?
I have problem even at the start of their integration guide: https://developers.soundcloud.com/docs/api/ios-quickstart#authentication
When, in AppDelegate, I write
var scurl: NSURL
scUrl = NSURL(string: "www.francescocrema.it")!
SCSoundCloud.setClientID(idCode,secret: secCode, redirectURL: scUrl)
when it gets executed, the app crashed with SIGABRT and no visible error!
Plus, I can't manage to translate this code to Swift
- (IBAction) login:(id) sender
{
SCLoginViewControllerCompletionHandler handler = ^(NSError *error) {
if (SC_CANCELED(error)) {
NSLog(#"Canceled!");
} else if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Done!");
}
};
[SCSoundCloud requestAccessWithPreparedAuthorizationURLHandler:^(NSURL *preparedURL) {
SCLoginViewController *loginViewController;
loginViewController = [SCLoginViewController
loginViewControllerWithPreparedURL:preparedURL
completionHandler:handler];
[self presentModalViewController:loginViewController animated:YES];
}];
}
Does someone know more about SoundCloud API?
Could you help me?
I am afraid SoundCloud API is not longer maintain by its team. I would recommend you to use your own library. I am using SoundCloud API as well so I decided to create one, maybe it can be useful for you.
ABMSoundCloudAPI on Github
Your redirectURL is invalid. SCRequest requires a URL with the scheme https:
NSAssert1([[aResource scheme] isEqualToString:#"https"], #"Resource '%#' is invalid because the scheme is not 'https'.", aResource);
Your Swift presentation code might look like this:
SCSoundCloud.requestAccess { (url) in
let loginViewController = SCLoginViewController(preparedURL: preparedUrl, completionHandler: nil)
self.present(loginViewController, animated: true)
}

Resources