Swift: How to post to Twitter from iOS app with certain hashtag? - ios

I'm fairly new to posting to social media via Swift in an iOS app but need to be able to post an image to Twitter under a certain hashtag (i.e the user's image is always posted under this certain hashtag regardless).
So far, my app can take a picture and access the user's photo library, but I have run into some trouble implementing post to Twitter.
I have looked at the following questions: Post on twitter from ios app
How to make an ios app post to twitter
But most of the links referenced are either gone or outdated. I have also looked into Sharekit (http://getsharekit.com) as this would do the posting to Twitter automatically it seems, however Sharekit is deprecated.
Ideally, I would like the user to be able to take their photo (I have this) give it a caption, etc WITHIN THE APP then when they press a button it more or less "silently" posts to Twitter WITH the hashtag that I will have set in the app. I am unsure as to how to accomplish this.
What is the best way/approach to posting an image to Twitter via Swift? The hashtag bit seems to be the more difficult step - how can I "force" a hashtag on the user's post?

What you're probably looking for is the Social framework and SLComposeViewController.
Using the setInitialText(_:) method you can add text to the tweet, though this doesn't really force anything, as the user still has the possibility to edit the tweet before publishing, and it doesn't really work "silently" either.
Posting an image is done with the addImage(_:) method.

Related

Tweeting a message using Swift and Parse

I'm currently writing a social networking app for iOS using Swift and the Parse SDK. My app is basically a UITableView that displays a timeline of messages from users that sign up for my app. But there is one part that I'm struggling with that I hope the community will be able to help me solve.
My problem is that when I want to be able to tweet the message that the user to my twitter followers. But I cant seem to figure out how to get message displayed in my timeline as the text for my tweet share sheet using the Social Framework built into iOS. I also have a Alert to be displayed when the user taps on a message to give a list of sharing options. I figure this alert is not the cause my issue. I will attach my source code for my TimelineTableViewController. Full code examples on how to active this logic in Swift is very helpful.
TimelineTableViewController

Facebook custom photo and video sharing action in iOS

I have video and photo sharing working fine in an iOS app using UIActivityViewController.
Now I want to upgrade it so that the app posts a custom OpenGraph story to the timeline. Something like "User posted Video from MySuperApp".
I've got the all the iOS side written, and I've got a Facebook app created and configured in the project, login, etc.
I'm a bit frustrated by the rest of the documentation, though:
The submission guidelines speak about a "user generated photos" permission that doesn't seem to be available anywhere in the app settings, or anywhere else in the documentation. Is that still required? Is there a similar permission for videos?
It says "Photos must be original and can only be those taken with a camera by the person who is publishing them". The app allows adding annotations/drawings on top of a photo. Does that still count as "original"? And I guess the normal image controls allow selecting images from an album, so I have no way to enforce this, do I? (Other than writing a completely custom camera control, I guess...)
The API allows to "stage" a photo for a story. Is it possible to stage a video, or do I need to upload it externally? Can I refer to a video in a user's album in a story?
Is it possible to use FBDialogs to post a story about a video, or do I need to write my own?
Update:
Current status: I wrote my own UIActivity to share on Facebook and my own activity view controller.
Making a custom story about a photo is straightforward, and covered by documentation and examples, but to summarize:
stage photo, returns url
create object, returns id
create action (returns id)
Make sure you set "explicitly_shared" to true, so the action appears in the timeline. It is a good idea to follow their recommendations for error handling as well, otherwise it is a pain to debug.
I am not further with videos, though. Uploading a video is easy ([FBRequest requestForUploadVideo]), but that returns an id. So far I have not been able to use this id in either an object or an action. Querying the graph API for that id doesn't return any information. The video appears on the timeline by itself as well.
I'm tempted to just ditch the custom story about the video.
Update:
Okay, based on the feedback here and on the Facebook group I have to assume that it is not possible to upload and share a video as part of a story. I'm going to strip the feature down to just upload the video to the album.

Initiate Facebook Group Chat from iOS App

I want my app to create a new Facebook group chat with certain people that opens either on Facebook's site in Safari or in the native Facebook app when the user presses a button. I want Facebook to handle the whole chat and my app only to initiate it somehow in the cleanest and least involved way possible. My app already uses the Facebook SDK to open an active FBSession, so I've already got login credentials.
Looking around online and in Facebook's docs, I can't find anything that suits my needs. The closest thing I found was in this answer containing a list of Facebook app URLs you can connect to that open the Facebook app to certain pages. There's "fb://chat/(initWithUID:)" and "fb://messaging/compose/(initWithUID:)". However, not only is there no explanation on how to use these, but people say that Facebook has changed these URLs (and does not have any documentation on them), so they don't work anymore unless I reverse-engineer new URLs (which could change again). Ugh, so close!
I also found examples on starting chats with the Facebook Chat API, but that involves logging into Facebook using some networking framework then writing my own GUI and model for sending messages, which I am only prepared to do as a last resort. There should be some way to let the Facebook app or website do all that. Does anyone know how I can do this?
I've found something very close, but I still don't see a way to make my app initialize it with the desired group of friends:
The Facebook SDK has a message dialog that can appear for sending messages to friends. This isn't exactly what I wanted but is good enough because it means that all the programming is already done for me by Facebook, and users should be able to see these messages on https://facebook.com and the Facebook apps. https://developers.facebook.com/docs/ios/share#message-dialog

Posting Video from IOS app to Users Facebook Wall

Im very new to Xcode and i'm trying to create a somewhat Social Networking app. At this point i'm not looking for it to be its own app but I want the app to have the ability to let the User sign into their Facebook Account and than Post a Video from the Camera Roll to their wall. I know it sounds simple but Ive look and all i can get are extremely confusing answers that don't make any sense.
Thanks in Advance.
Looking for
1 allow Facebook Login
2) Post Video from Camera Roll to their facebook.
If possible It would be cool to have a thumbnail of the video before they post it. Kind of like instagram. Thanks!
First off, you need to create an app for your iOS app on Facebook. Then use the tokens or keys they provide you with, in order for your app to be able to do anything with Facebook.
Facebook has pretty good instructions on how to set up Facebook login on your app. You can find detailed, step-by-step instructions here. Depending on what type of login you need, you can choose a suitable option.
I have not posted actually files so far onto a Facebook feed/wall. But I have set up sharing of posts. You can find instructions for that here.
Hope this helps.

iOS TWTweetComposeViewController - Posting in background

I'm trying to integrate twitter in iOS5 app.
Using Twitter framework in my app, can I post the message in the background?
I know that using TWTweetComposeViewController, it will show a view and then it will post.
Is this possible?
The answer is no. The whole point of having the View Controller is to allow the User to see and dictate what exactly will be posted without interference from the App apart from the initial text which the user also has the option to change. It stops apps abusing the Twitter accounts from posting spam etc.
The Apple Documentation clearly states:
Although you may perform Twitter requests on behalf of the user, you cannot append text, images, or URLs to tweets without the user’s knowledge. Hence, you can set the initial text and other content before presenting the tweet to the user but cannot change the tweet after the user views it.
You can't do this using TWTweetComposeViewController. You can do this using TWRequest provided the user authorizes your app to access their Twitter account(s).

Resources