Changes coming in Version 1.1 of the Twitter API in iPhone - iphone

I am using twitter API version V1.0 for my new iphone application .I am successfully able to do this using twitters v1.0 of the API and all works perfectly. Simply making a request to http://api.twitter.com/1/statuses/user_timeline.json?screen_name=userid retrieves all the information that I require.
since v1.0 has been deprecated and V1.1 requires authentication for each request, I get a bad authorization error (HTTP response status: 400)using this API.
What are the Changes i need to do in my appication .how to generate OAuth request headers,Do i need register my application ?How can i get authentication for new version?
I hope the above makes sense and any help would be appreciated.
Thanks in advance.

Visit https://dev.twitter.com/docs/ios/making-api-requests-slrequest
https://dev.twitter.com/docs/oauth/xauth
u can get the authentication using following method:
NSString *base64 = #"Basic NFRLWGlZY3l1aHJ4OVJaUWI5RW5BOmdVMXlvcVV6YzBNZUhUQmFXdVRZU2NtZHlIWDFOZXhwZmxqRE16bm01aw==";
//oauth_consumer_secret,oauth_consumer_key
NSURL *urlAPI = [NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/oauth2/token"]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlAPI];
[request setDelegate:self];
[request setRequestMethod:#"POST"];
[request addRequestHeader:#"Authorization" value:base64];
[request addRequestHeader:#"Content-Type" value:#"application/x-www-form-urlencoded;charset=UTF-8"];
[request setPostValue:#"client_credentials" forKey:#"grant_type"];
In response u will get the authtoken for your application like this
{"token_type":"bearer","access_token":"AAAAAAAAAAAAAAAAAAAAAMddRQAAAAAAXRP6Axur1RS%2Fv9YFtJ7TijyPAGo%3DpmNowwOGf3dZTHDiH2gnCcv7qNIyGZcyV2IW5YFTBs"}

Related

ios managing authentication tokens from NSURLRequest / HTTP request

When I make a POST request to sign in from within the iPhone app I am developing, the request returns an authentication token that I can successfully store in an NSString to be used throughout the rest of the app.
However, for any request after the sign in, I must pass it this authentication token so the request knows that a user is logged in. What is the complete way to do this for an NSURLRequest / what parameters/values must i specify for the NSURLRequest? Thank you in advance.
These NSURLRequest methods might help you
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"yoururl.com"]];
[request setHTTPMethod: #"POST" ];
[request setValue:#"yourtoken" forHTTPHeaderField:#"header field"];
[request setHTTPBody: dataifneeded ];

ASIHTTPRequest Integrate Twitter

I need your help. I have been switching from various libraries trying to find the suitable one to integrate Twitter in my application.
A while back i found out that i could use ASIHTTPRequest to send tweets from my app. I need to know if there's any tutorial or sample code available.
And i have already looked at share-kit and i prefer to integrate Twitter using ASIHTTPRequest
note: I have created my project using ARC, and it shoudl support both iOS4 and 5.
Twitter's documentation says that you have to make GET or POST HTTP requests with the appropriate form data (key-value pairs). For example, to post a status update, you can do:
NSURL *url = [NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:#"Accept" value:#"*/*"];
[request addRequestHeader:#"onnection" value:#"close"];
[request addRequestHeader:#"Content-Type" value:#"application/x-www-form-urlencoded"];
[request addRequestHeader:#"Content-Length" value:#"17"];
[request addRequestHeader:#"Host" value:#"api.twitter.com"];
[request setPostValue:#"User's new status" forKey:#"status"];
// set here completion/error handlers
[request startAsynchronous];
More documentation on Twitter's REST/HTTP API: https://dev.twitter.com/docs
For authetication, you'll need some kind of OAuth library. Here's Karl Adam's MPOAuth, with few additions and corrections by me: https://github.com/H2CO3/MPOAuthiOS
On iOS 5.x, you can use Apple's default, and easy to use Twitter.framework: http://developer.apple.com/library/ios/#documentation/Twitter/Reference/TwitterFrameworkReference/_index.html

Posting JSON from iOS to Rails 3.1 (Stringify_keys error)

I'm trying to create a user acount on my rails backend via json from an iPhone app. Here is what is currently being posted to the server:
Started POST "/patients" for 127.0.0.1 at 2011-11-27 20:52:29 -0800
Processing by PatientsController#create as HTML
Parameters: {"patient"=>"{\"password\":\"password\",\"password_confirmation\":\"password\",\"email\":\"testagain\"}"}
WARNING: Can't verify CSRF token authenticity
Completed 500 Internal Server Error in 1ms
NoMethodError (undefined method `stringify_keys' for #<String:0x00000104a354f8>):
app/controllers/patients_controller.rb:43:in `new'
app/controllers/patients_controller.rb:43:in `create'
By posting straight from the browser these are the paramaters that are submitted:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"H2iYdzdfokQs91AAozb+taMTdV2y5xLRaCni5XKQN4w=", "patient"=>{"email"=>"test", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Create Patient"}
From what I have read elsewhere the stringify_keys means that the actions expects a hash (which I thought I almost reconstructed) since I am using this code to create a new user:
#patient = Patient.new(params[:patient])
I also believe that the authenticity token doesn't matter if I'm posting using JSON format... does it matter?
Over all question: Is this the right approach to be posting to a rails backend from an iphone app? Recreating the parameters hash? Would appreciate any nudges in the right direction.
For completeness sake here is the code snippet I'm using to post from my iOS app:
NSDictionary *json = [self createSignUpDictionary];
NSURL *url = [NSURL URLWithString:#"http://localhost:3000/patients"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:#"Content-Type" value:#"application/json"];
[request addRequestHeader:#"Accepts" value:#"application/json"];
[request setPostValue:[json JSONString] forKey:#"patient"];
[request startAsynchronous];
You will most likely have to disable the authentication token verification for your action.
Just put the following line in your controller and everything should work.
protect_from_forgery :except => :index
However if you do that make sure that you have some form of custom protection on your #create function. You can read this for more info: http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html

Web service in iphone

Hi everyone i am new to iphone development.I am working on an application which required to check and register the user name and password using soap web service.could anyone help me how to do that with that web service.i have two text fields for login.and button to check if the credentials are correct or not.
Maybe this is helpful for you: http://devmylife.com/?p=111
The website disappeared, you can find it here: http://web.archive.org/web/20100704000223/http://devmylife.com/?p=111
ASIHTTP SOAP Request
First of all down http://www.soapui.org/ or any packet sniffing app. and try requesting your SOAP-service. When you get the SOAP-packet, you have to exactly generate the same packet using ASIHTTP. You have to add headers yourself.
Download latest version of ASIHTTP
NSString *urlString = URL_HOST;
NSString *soapMessage = [NSString stringWithFormat:#"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
"<SOAP-ENV:Body>"
"<m:getInboxPosts xmlns:m=\"urn:finditnearwsdl\">"
"<input xsi:type=\"tns:InboxPostsRequest\">"
"<session_id xsi:type=\"xsd:string\">%#</session_id>"
"<page_size xsi:type=\"xsd:int\"></page_size>"
"<offset xsi:type=\"xsd:int\"></offset>"
"</input>"
"</m:getInboxPosts>"
"</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>" ,adBo.sessionId];
NSLog(soapMessage);
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlString];
[request appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding];
[request addRequestHeader:#"SOAPAction:" value:SOAP_ACTION];
[request startSynchronous];

Unable to POST data from IPhone using google account authentication

I'm working on an IPhone application that works with a Google App Engine application. I manage to get logged by using a google account and I get the authentication token. I'm also able to GET data from the GAE service (I did it after reading another question written here) but now I need to POST data so I need to send the authentication token in the header of the POST request. I tried several options but none of them worked.
Here is the code I use to put that auth into the header:
NSString* urlStr = [NSString stringWithFormat:#"%#%#", HOST, url];
NSMutableURLRequest* urlPost = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
NSString* authStr = [NSString stringWithFormat:#"GoogleLogin auth=%#", token];
[urlPost addValue:authStr forHTTPHeaderField:#"Authorization"];
but it doesn't work.
Any help?
You need to use [request setHTTPMethod: #"POST"] and [request setHTTPBody: postdata] to properly configure the POST components. See the NSMutableURLRequest docs for more details.
Whenever I'm troubleshooting a problem related to HTTP, the first tool I'll grab is Charles HTTP Proxy. It will show you the entire request and response for closer examination.
If you're authenticating against an App Engine app, you need to obtain and send an authentication cookie, rather than using the GoogleLogin authentication. The source of appengine_rpc.py in the Python SDK demonstrates how.