Tech Forum Network

Programming, technical solutions and hot scripts
Home » Programming » Basic Facebook / Twitter URL Handlers format

Basic Facebook / Twitter URL Handlers format

May 29, 2012 Posted by forumadmin under Programming
Comments off

I’m pretty sure an hour after I post this I may find the answer but I’ve been looking for over an hour already and can’t seem to work it out. So here goes..

I’d like to put some simple “Contact Us” links in to my app which opens my profile in one of these twitter apps if available …. “Twitter”, “Tweetbot”, “Twitterriffic”, or Facebook falling back to Safari if none are available. I don’t wish to add a full API for twitter etc, as its merely a contact page, I have no need to access their time lines, or know their user ID’s etc.

The Tweetbot APP and handler which I use on my phone works fine (see below) and opens my Profile Page, however I can’t seem to get the default Facebook or Twitter app’s work, the applications launch but don’t got to my respective profile page (I’ve obviously left out the testing code but these are the lines which call the applications) ….

//Twitter
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://twitter.com/MyTwitterID"]];

//Tweetbot - WORKS!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tweetbot:///user_profile/MyTwitterID"]];

//Fall Back to Safari - WORKS!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/MyTwitterID"]];

//Facebook 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/MyFbID"]];

Now I got a fair bit of information here , but am unable to get it working apart from for Tweetbot and Safari. I’m guessing the URL part is in the wrong format, but I can’t find anywhere that explains how it should be. Google searching brings up pages with twitter and facebook tags but no helpful information, and the Twitter API documentation is far too detailed for the simple implementation I want to do. Can anyone help me with the right URL formats?


[EDIT] Took me more than an hour but here it is for Twitter at least ..

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];

Still working on the Facebook one!! Can’t take credit for the answer though I stumbled across it here

When I get the Facebook one working too I’ll post my code here with all the bits in case it helps someone else!

Plasma


EDIT 2: Ok here is my code (I’ve removed my website URL and also my facebook ID’s but you’ll get the idea …. It pops a UI Action Sheet with the Contact Us options.. Hope its of use to someone else.

#pragma mark - Contact Us Methods
- (IBAction)openContact {   

    UIActionSheet *popupContact = [[UIActionSheet alloc] initWithTitle:@"Contact Us" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Twitter", @"Facebook", @"Email", @"Visit our website", nil];

    popupContact.actionSheetStyle = UIActionSheetStyleDefault;

    [popupContact showInView:self.parentViewController.tabBarController.view];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    NSString *twitterUserName  = @"MyTwitterName";

    //Facebook ID (not the page name) check the FB urls for id=XXXXXXXXXXXXXXXX
    NSString *facebookUserID = @"XXXXXXXXXXXXXXX";


    UIApplication *app = [UIApplication sharedApplication];

    switch(buttonIndex){
        case 0: {
            //Contact Us By Twitter 

            //Twitter Default
            NSURL *twitterURL = [NSURL URLWithString:[NSString stringWithFormat:@"twitter://user?screen_name=%@", twitterUserName]];
            if ([app canOpenURL:twitterURL]) 
            {
                [app openURL:twitterURL];
                return;
            }

            //Tweetbot 
            NSURL *tweetbotURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetbot:///user_profile/%@", twitterUserName]];
            if ([app canOpenURL:tweetbotURL]) 
            {
                [app openURL:tweetbotURL];
                return;
            }

            // Tweetie: http://developer.atebits.com/tweetie-iphone/protocol-reference/
            NSURL *tweetieURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetie://user?screen_name=%@", twitterUserName]];
            if ([app canOpenURL:tweetieURL])
            {
                [app openURL:tweetieURL];
                return;
            }

            // Birdfeed: http://birdfeed.tumblr.com/post/172994970/url-scheme
            NSURL *birdfeedURL = [NSURL URLWithString:[NSString stringWithFormat:@"x-birdfeed://user?screen_name=%@", twitterUserName]];
            if ([app canOpenURL:birdfeedURL])
            {
                [app openURL:birdfeedURL];
                return;
            }

            // Twittelator: http://www.stone.com/Twittelator/Twittelator_API.html
            NSURL *twittelatorURL = [NSURL URLWithString:[NSString stringWithFormat:@"twit:///user?screen_name=%@", twitterUserName]];
            if ([app canOpenURL:twittelatorURL])
            {
                [app openURL:twittelatorURL];
                return;
            }

            // Icebird: http://icebirdapp.com/developerdocumentation/
            NSURL *icebirdURL = [NSURL URLWithString:[NSString stringWithFormat:@"icebird://user?screen_name=%@", twitterUserName]];
            if ([app canOpenURL:icebirdURL])
            {
                [app openURL:icebirdURL];
                return;
            }

            // Fluttr: no docs
            NSURL *fluttrURL = [NSURL URLWithString:[NSString stringWithFormat:@"fluttr://user/%@", twitterUserName]];
            if ([app canOpenURL:fluttrURL])
            {
                [app openURL:fluttrURL];
                return;
            }

            // SimplyTweet: http://motionobj.com/blog/url-schemes-in-simplytweet-23
            NSURL *simplytweetURL = [NSURL URLWithString:[NSString stringWithFormat:@"simplytweet:?link=http://twitter.com/%@", twitterUserName]];
            if ([app canOpenURL:simplytweetURL])
            {
                [app openURL:simplytweetURL];
                return;
            }

            // Tweetings: http://tweetings.net/iphone/scheme.html
            NSURL *tweetingsURL = [NSURL URLWithString:[NSString stringWithFormat:@"tweetings:///user?screen_name=%@", twitterUserName]];
            if ([app canOpenURL:tweetingsURL])
            {
                [app openURL:tweetingsURL];
                return;
            }

            // Echofon: http://echofon.com/twitter/iphone/guide.html
            NSURL *echofonURL = [NSURL URLWithString:[NSString stringWithFormat:@"echofon:///user_timeline?%@", twitterUserName]];
            if ([app canOpenURL:echofonURL])
            {
                [app openURL:echofonURL];
                return;
            }

            // --- Fallback: Mobile Twitter in Safari
            NSURL *safariURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://mobile.twitter.com/%@", twitterUserName]];
            [app openURL:safariURL];
            return;

        }
        case 1: {
            //Facebook
            NSURL *facebookURL = [NSURL URLWithString:[NSString stringWithFormat:@"fb://profile/%@", facebookUserID]];
            if ([app canOpenURL:facebookURL]) 
            {
                [app openURL:facebookURL];
                return;
            }

            // --- Fallback: Mobile Facebook in Safari
            NSURL *safariURL = [NSURL URLWithString:@"https://touch.facebook.com/MyFBName"];
            [app openURL:safariURL];
            return;

        }
        case 2:
            //Email           
            [app openURL:[NSURL URLWithString:@"mailto://support@mywebsite.co.uk?subject=Important%20Email&body="]];
            return;


        case 3:
            //Visit The Website
            [app openURL:[NSURL URLWithString:@"http://www.mywebsite.co.uk"]];
            return;

        case 4:
            //Cancel
            return;

    } 

}
Asked By – Plasma        Read Answers         Answers :



Stack Exchange



log in
|
careers
|



chat
|
meta
|
about
|
faq

More Related Questions

  • Facebook twitter sharing in iOS- native or on web
    We have a server to which if we send a request to share on twitter/facebook, it will ask for credentials and then post. However, I am not sure, if for iOS applications, Apple allows this kind of inte...
  • Facebook share button on my app – Do I have to use the facebook SDK?
    I want to implement the simplest Share this button on my app that the user can tap and share that he is using the app on his Facebook wall. Do I have to integrate the facebook sdk in my app just for t...
  • FBRequest on iphone 5 [closed]
    I'm using FBRequest for friends list in send gift and invite friends components - on iphone 4 requests look good but on iphone 5 I get pop without styles and no friends list. Someone came across this?...
  • Facebook Ios sdk logging in
    I am trying to create a function with iOS facebook sdk where I will be able to login and if I am logged in I will be able to see the nslog string "logged in". However I am not seeing it the string at ...
  • How do I post on friends walls?
    I am using the following code to post on device user's wall. I have managed to get the friends list and their ids too. Using the friend's id how can I use the following code to post on selected friend...
  • Sharing with iOS 6.0 native Facebook integration: "Posted via my app name"?(Resolved)
    I have just integrated facebook into my app via ios 6 but I have an issue when posting on my wall. It simply says "post via ios app". I want it to say "posted via the app name". I have made an app ide...
  • Sharing with iOS 6.0 native Facebook integration: "Posted via my app name"?
    I have just integrated facebook into my app via ios 6 but I have an issue when posting on my wall. It simply says "post via ios app". I want it to say "posted via the app name". I have made an app ide...
  • Sharing with iOS 6.0 native Facebook integration: "Posted via my app name"?
    I have just integrated facebook into my app via ios 6 but I have an issue when posting on my wall. It simply says "post via ios app". I want it to say "posted via the app name". I have made an app ide...
  • Facebook Help, iOS SDK
    I am currently making a Facebook iOS Application and In the app I am trying to get the users Facebook wall and put it in a UITable View. So Far I Have: [facebook requestWithGraphPath:@"me/home" and...
  • Facebooks FBConnect SDK issues on iOS
    I'm using FBConnect sdk in order to publish posts to a user's profile via my application. I'm having a number of problems with this: When the relevant code runs for the first time on the device, the ...
Email
Tags: facebook, ios, objective-c, openurl, twitter

Comments are closed.

« Eclipse CDT: Symbol cout could not be resolved
facebook share page cant show &(ampersand) mark? »
Tech Forum Network powered by WordPress and The Clear Line Theme