{"id":126,"date":"2013-08-20T00:26:49","date_gmt":"2013-08-19T18:56:49","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=126"},"modified":"2023-01-20T18:56:10","modified_gmt":"2023-01-20T13:26:10","slug":"twitter-integration-in-ios","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/","title":{"rendered":"Twitter Integration in iOS"},"content":{"rendered":"<p style=\"text-align: justify;\"><span style=\"line-height: 1.714285714; font-size: 1rem;\">Lets assume you have developed a great application and now you want to make it &#8220;Social&#8221;. Facebook and Twitter are the two most popular social networking sites.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1rem; line-height: 1.714285714;\">In this tutorial, we will learn how to deep integrate <\/span><strong style=\"font-size: 1rem; line-height: 1.714285714;\">Twitter<\/strong><span style=\"font-size: 1rem; line-height: 1.714285714;\"> in your application. Before starting, I am assuming that you are familiar with the <\/span><strong style=\"font-size: 1rem; line-height: 1.714285714;\">Objective C<\/strong><span style=\"font-size: 1rem; line-height: 1.714285714;\"> syntax and <\/span><strong style=\"font-size: 1rem; line-height: 1.714285714;\">Xcode<\/strong><span style=\"font-size: 1rem; line-height: 1.714285714;\"> environment and have basic knowledge of <\/span><strong style=\"font-size: 1rem; line-height: 1.714285714;\">iOS<\/strong><span style=\"font-size: 1rem; line-height: 1.714285714;\">.<\/span><\/p>\n<p><strong><span style=\"color: #333399;\">1. Frameworks<\/span> <\/strong>&#8211;\u00a0<span style=\"font-size: 1rem; line-height: 1.714285714; text-align: justify;\">To Integrate with Twitter we will use the &#8220;Accounts&#8221; framework and the &#8220;Social&#8221; framework.You need to add these frameworks into your project. &#8220;Accounts&#8221; framework lets you to not worry about the OAuth implementation that Twitter requires.<\/span><\/p>\n<p><span style=\"color: #333399;\"><strong style=\"text-align: justify;\">2. Accounts in Settings<\/strong><\/span><span style=\"text-align: justify;\"> &#8211; To check if the user already has an account in the Settings app use:<\/span><\/p>\n<pre>if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])\r\n{\r\n\/\/ Yay! a twitter account is already set up.\r\n}\r\nelse\r\n{\r\n\/\/ Yieks need to set up an account\r\n}<\/pre>\n<p style=\"text-align: justify;\">If the account is not already set in the Settings, we would need to take the user to the Settings page, which is not possible in iOS as it is a private API. Work around &#8211; When you try to access a Twitter account even when an account is not set in the settings, iOS presents user an alertView that no account is set in the Settings. It can then take user to the settings app to set the new account. We are going to use this as a workaround. To prompt user to go to the Settings page use:<\/p>\n<pre>SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];\r\n\r\ntweetSheet.view.hidden=TRUE;\r\n\r\n[self presentViewController:tweetSheet\r\nanimated:NO\r\ncompletion:^{\r\n[tweetSheet.view endEditing:YES];\r\n}];<\/pre>\n<p style=\"text-align: justify;\"><span style=\"color: #333399;\"><strong>3. Access the Account<\/strong><\/span> &#8211; Time to access the Account of the user: To access account, we first need to get an <em>AccountStore<\/em> Object. Then from the Account store we get the <em>Account<\/em> object as:<\/p>\n<pre>ACAccountStore *accountStore = [[ACAccountStore alloc] init];\r\nACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:\r\n\r\nACAccountTypeIdentifierTwitter];\r\n[accountStore requestAccessToAccountsWithType:accountType options:nil\r\n\r\ncompletion:^(BOOL granted, NSError *error)\r\n{\r\nif (granted == YES)\r\n{\r\nNSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];\r\n\r\n\/\/For the sake of the example we are going to just access the last account we find\r\nACAccount *tempAccount = [arrayOfAccounts lastObject];\r\n\/\/Hooh haah.. Got the account :D\r\n}\r\n}];<\/pre>\n<p style=\"text-align: justify;\"><span style=\"color: #333399;\"><strong>4. Request to Twitter API<\/strong><\/span> &#8211;\u00a0Now to make a request to the twitter API we just need to create a <em>SLRequest<\/em> and add this account to the request. For example to simply get the home_timeline of the user you can use :<\/p>\n<pre>NSURL *tweetURL = [NSURL URLWithString:@\"https:\/\/api.twitter.com\/1.1\/statuses\/home_timeline.json\"];\r\n\r\nSLRequest *tweetRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter\r\nrequestMethod:SLRequestMethodGET\r\nURL:tweetURL\r\nparameters:nil];\r\n\r\n[tweetRequest setAccount:userAccount];\r\n\r\n[tweetRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {\r\n\r\nif (!error)\r\n{\r\n\/\/do something with the response data.\r\n}\r\nelse\r\n{\r\n[[[UIAlertView alloc]initWithTitle:@\"Error\"\r\nmessage:[error description]\r\ndelegate:nil\r\ncancelButtonTitle:@\"OK\"\r\notherButtonTitles:nil, nil] show];\r\n}\r\n}];<\/pre>\n<p style=\"text-align: justify;\">And thats it .. You can get the list of all the possible twitter requests at <a href=\"https:\/\/dev.twitter.com\/docs\/api\/1.1\">https:\/\/dev.twitter.com\/docs\/api\/1.1<\/a><\/p>\n<p style=\"text-align: justify;\">Have fun !!<\/p>\n<p><strong>Looking for a mobile solution with social media integration?\u00a0<\/strong><strong>Contact sales@innovationm.com<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lets assume you have developed a great application and now you want to make it &#8220;Social&#8221;. Facebook and Twitter are the two most popular social networking sites. In this tutorial, we will learn how to deep integrate Twitter in your application. Before starting, I am assuming that you are familiar with the Objective C syntax [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":368,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,63],"tags":[160,91,164,47,48],"class_list":["post-126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-social-media-integration","tag-ios","tag-ios7","tag-social-media-integration","tag-twitter","tag-twitter-integration"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Twitter Integration in iOS | InnovationM Blog<\/title>\n<meta name=\"description\" content=\"Learn how to integrate Twitter with iOS applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Twitter Integration in iOS | InnovationM Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to integrate Twitter with iOS applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-19T18:56:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-20T13:26:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2013\/08\/InnovationM-iOS-Twitter-Integration1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"642\" \/>\n\t<meta property=\"og:image:height\" content=\"364\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Twitter Integration in iOS\",\"datePublished\":\"2013-08-19T18:56:49+00:00\",\"dateModified\":\"2023-01-20T13:26:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/\"},\"wordCount\":337,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/08\\\/InnovationM-iOS-Twitter-Integration1.png\",\"keywords\":[\"iOS\",\"iOS7\",\"Social Media Integration\",\"Twitter\",\"Twitter Integration\"],\"articleSection\":[\"iOS\",\"Social Media Integration\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/\",\"name\":\"Twitter Integration in iOS | InnovationM Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/08\\\/InnovationM-iOS-Twitter-Integration1.png\",\"datePublished\":\"2013-08-19T18:56:49+00:00\",\"dateModified\":\"2023-01-20T13:26:10+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Learn how to integrate Twitter with iOS applications.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/08\\\/InnovationM-iOS-Twitter-Integration1.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/08\\\/InnovationM-iOS-Twitter-Integration1.png\",\"width\":642,\"height\":364,\"caption\":\"Twitter Integration in iOS\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/twitter-integration-in-ios\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Twitter Integration in iOS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Twitter Integration in iOS | InnovationM Blog","description":"Learn how to integrate Twitter with iOS applications.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/","og_locale":"en_US","og_type":"article","og_title":"Twitter Integration in iOS | InnovationM Blog","og_description":"Learn how to integrate Twitter with iOS applications.","og_url":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/","og_site_name":"InnovationM - Blog","article_published_time":"2013-08-19T18:56:49+00:00","article_modified_time":"2023-01-20T13:26:10+00:00","og_image":[{"width":642,"height":364,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2013\/08\/InnovationM-iOS-Twitter-Integration1.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Twitter Integration in iOS","datePublished":"2013-08-19T18:56:49+00:00","dateModified":"2023-01-20T13:26:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/"},"wordCount":337,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2013\/08\/InnovationM-iOS-Twitter-Integration1.png","keywords":["iOS","iOS7","Social Media Integration","Twitter","Twitter Integration"],"articleSection":["iOS","Social Media Integration"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/","url":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/","name":"Twitter Integration in iOS | InnovationM Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2013\/08\/InnovationM-iOS-Twitter-Integration1.png","datePublished":"2013-08-19T18:56:49+00:00","dateModified":"2023-01-20T13:26:10+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Learn how to integrate Twitter with iOS applications.","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2013\/08\/InnovationM-iOS-Twitter-Integration1.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2013\/08\/InnovationM-iOS-Twitter-Integration1.png","width":642,"height":364,"caption":"Twitter Integration in iOS"},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/twitter-integration-in-ios\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Twitter Integration in iOS"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/368"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}