ios - Provide Default Twitter account for authentication -


i want display feeds of 1 specific twitter page. regardless of user is, want able specify number of tweets , twitter user retrieve (this hardcoded)

i have used following code start authentication

self.accountstore = store; acaccounttype *twitteraccounttype = [self.accountstore accounttypewithaccounttypeidentifier: acaccounttypeidentifiertwitter];

there lot of code below this, follow twitter documentation, basically, throw uialertview if no accounts set up.

i want take account fact that, users of app: 1 - might not have twitter account 2 - not use twitter on phone , not set in settings

the twitter feed serves news feed in application, question is,

is there anyway, can provide twitter api default user, hardcoded, without having go through accounts ?

i want know sort of info accountstore pulling, perhaps replicate , send twitter api after building similar structure.

i bit new iphone programming forgive me if of obvious.

thank time.

i found answer helps me requirements,

my requirements developing iphone app , needed specific tweets 1 particular user on twitter. while easy using old twitter api, using v1.1, user authentication needed.

while ios provides own social sdk, wanted consider fact users might not have twitter or not signed in on phones , still receive feeds. research, did not find solutions resulted in checking iphone settings of user make sure have set twitter account.

so since these constraints, decided @ creating web service using php, authenticate twitter , pull tweets needed. encode them json , echo it.

then ios app, called web service , deserialized , used how needed to.

now code.

most of answer how use php new twitter api can found here: https://github.com/j7mbo/twitter-api-php. grab files here , can see example gives. have given small 1 below.

here of steps needed use

  • create app on twitter. go here https://dev.twitter.com/, log in twitter account. once there need create application.
  • grab files above , place twitterapiexchange.php on server
  • create php file , put require_once('twitterapiexchange.php'); @ top
  • after creating application, dashboard, given information need authenticate twitter api. use in php so

    $settings = array( 'oauth_access_token' => "your_oauth_access_token", 'oauth_access_token_secret' => "your_oauth_access_token_secret", 'consumer_key' => "your_consumer_key", 'consumer_secret' => "your_consumer_secret" );

once have set array can move onto specify need set things require

$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; $getfields = '?screen_name=screen_name_you_want&count=number_of_tweets_you_want'; $requestmethod = 'get'; 

the url states resource want after script authenticates. below parameters. screen name , number of tweets want retrieve. request method protocol get. if want post timeline, need use post modify apps access dev account. currently, app has read access needed that.

then time execute

$twitter = new twitterapiexchange($settings);  $tweets = $twitter->setgetfield($getfield)              ->buildoauth($url, $requestmethod)              ->performrequest(); 

if see example on github j7mbo, echoes whole timeline, can see looks like, wanted dive deeper , tweets.

$tweet_array = array(); $index = 1; foreach($tweets $feed=>$item) {    $arr_index = 'tweet'.$index;    $tweet_array[$arr_index] => $item['text'];    $index++; }  echo json_encode($arr_index); 

this echo json "tweet1"=>"latest tweet","tweet2"=>"second latest tweet"

from xcode can call url , json feeds , use how want.

on side note: whenever script run, takes while authentication , retrieve feeds , since targeting ios app, might best apply caching. depending on how user in question updates twitter, can have time_limit. whenever retrieve tweets store in database. if next user requests tweets, check time limit, if less, retrieve db, if has passed time limit, update database , send user new results.

i thank j7mbo github library, , mzimmerman points out easier workaround using tumblr.

thanks.


Comments