sharekit:OAuth authentication failed for twitter - iphone

Some time I am getting the error message OAuth Authentication faileed while I am trying to login/share the date to Twitter using sharekit.Can any one help why I am getting this error?
#define SHKTwitterUseXAuth 0 is set in SHKConfig.h file

Some times this authentication failed error message is coming due to c change in twitter APIs and may be not updated in Sharekit.
Please verify in SHKTwitter.m that in init method the authorizeURL ,requestURL and accessURL should be like below,i.e add api before twitter.
self.authorizeURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/authorize"];
self.requestURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/request_token"];
self.accessURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/access_token"];
and in sendStatus method verify https should be there as below
OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1/statuses/update.json"]
consumer:consumer
token:accessToken
realm:nil
signatureProvider:nil];

Related

How to attach geolocation to a tweet using TWRequest

I'd like to attach the location of the user to a TWRequest. I've tried to modify the url (with something like this: "http://api.twitter.com/1/statuses/update.json?lat=37.76893497&long=-122.42284884") but the response was "401 Unauthorized" or "400 Bad Request".
My TWRequest:
TWRequest *postRequest = [[TWRequest alloc] initWithURL:
[NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:[tweet text] forKey:#"status"] requestMethod:TWRequestMethodPOST];
Thanks in advance.
You attempt to perform request which requires authorization. Just initialize account property.
Look at a good article about Twitter API: http://iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html
UPD: And you can't mix POST and GET variables, I mean you have to specify all parameters to NSDictionary (POST parameters), not to URL.
NSURL *updateURL = [NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[tweet text], #"status",
#"-122.42284884", #"long",
#"37.76893497", #"lat", nil];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:updateURL
parameters:dict
requestMethod:TWRequestMethodPOST];
UPD2: If geo-location isn't work, check if location is enabled for twitter account (go to Twitter site - Settings - Account - Tweet Location). Look at the REST API documentation on Twitter site update request section:
About geo
Any geo-tagging parameters in the update will be ignored if geo_enabled for the user is false (this is the default
setting for all users unless the user has enabled geolocation in their
settings)

OAMutableURLRequest - NSURLErrorDomain error -1012

I'm getting this error trying to post a request to hattrick.org using SAOAuthTwitterEngine Oauth authentication.
With all the GET requests everything works fine, but only one call must be in POST with a JSON string and this one doesn't work.
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn't be completed. (NSURLErrorDomain error -1012.).
I'm sure the request must be in http!
Here the code.
NSURL *finalURL = [NSURL URLWithString:path];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:finalURL
consumer:self.consumer
token:_accessToken
realm:nil
signatureProvider:nil];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:[[NSData alloc]initWithContentsOfFile:body]];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest: request delegate: self didFinishSelector:#selector(testApiCallResult:didFinish:) didFailSelector: #selector(testApiCallResult:didFail:)];
return responseBodyToReturn;
I don't know how to solve this error.
I think that you occurred in a bug on the library...
Try with another, my suggestion is to use this:
gdata-objectivec-client

could not authenticate OAuth while using twitter from sharekit in iphone app

I m implementing facebook & twitter share using sharekit in iphone app. Facebook share is working fine but twitter share gives error "could not authenticate OAuth".
I was having the same problem - this fixed it:
https://github.com/ideashower/ShareKit/issues/229
Summary:
Change SHKTwitter.m in lines 54-56 from
https://twitter.com/
to
https://api.twitter.com/
like this:
self.authorizeURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/authorize"];
self.requestURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/request_token"];
self.accessURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/access_token"];
and in line 323, from http to https:
OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1/statuses/update.json"]
consumer:consumer
token:accessToken
realm:nil
signatureProvider:nil];`

creating JSON request URL in Objective C via DropBox SDK for iPhone

I'm rather new to trying to figure out how JSON and the DropBox API function with the iphone SDK that DB has release for the iPhone. I understand how both technologies work in general and that you have to build a dictionary into a request and get another dictionary back, but I can't find a solid example of how to do anything specifically enough online in Objective C.
I just need one example of how to retrieve for instance the user's profile information by creating a JSON request to fetch info from the drop-box server.
I've been able to log the user in and linking the device using the consumer key and consumer secret but what's next I'm a little at a loss.
MANY thanks for any guidance or examples.
To send your data
Example for POST methods:
url = #"https://api.dropbox.com/<version>/account/"
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:value forKey:#"callback"];
Example for GET methods (URL queries):
NSString *urlString = [[[NSString alloc] initWithString:#"https://api.dropbox.com/<version>/account/info
"] autorelease];
urlString = [urlString stringByAppendingFormat:#"?callback=whatever&status_in_response=something"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestDidFinishForThreadID:)];
[request startAsynchronous];
To retrieve JSON values and convert them into Dictionary
SBJsonParser *json = [[SBJsonParser alloc] init];
NSDictionary *dict = (NSDictionary*)[json objectWithString:responseString];
You will need JSON Framework: http://code.google.com/p/json-framework/
And also ASIHTTPRequest: http://allseeing-i.com/ASIHTTPRequest/
Haven't tested it with dropbox, but should be this way.

HTTP Authentication Headers for IIS windows authentication

I have a web site hosted on IIS with windows authentication. I am trying to access it in one of my iPhone web application. Presently i am using this code, but it is not working.
NSString *authString = [[[NSString stringWithFormat:#"%#:%#", #"myusername", #"mypassword"]dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];
authString = [NSString stringWithFormat: #"Basic %#", authString];
**[requestObj setValue:authString forHTTPHeaderField:#"Authorization"];**
my web app is hosted with windows authentication. but here i am using basic. can any one post what is the correct http header for it.
Thanks..
I think the main difference is you need to specify the domain you are authenticating against as well as the username and password. Something like this should work. I've used a synchronous request for brevity, ideally you should use an ASINetworkQueue or NSOperationQueue to perform the request.
NSString *username = #"test";
NSString *password = #"test";
NSString *domain = #"test";
NSURL *url = [NSURL URLWithString:#"http://myurl"];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUseSessionPersistence:YES];
[request setUsername:username];
[request setPassword:password];
[request setDomain:domain];
[request start];
if ([request error]) {
if ([[request error] code] == ASIAuthenticationErrorType) {
//Authentication failed
}
} else {
NSLog([request responseString]);
}
I don't have access to a Windows server to test this, but I have tested NTLM in the past so it should work... :)
Windows authentication (NTLM) isn't as simple as basic authentication. NTLM requires more than one webrequest to negotiate the security so there isn't a static HTTP header you can send to log in.
You can use the third-party ASIHTTPRequest library to perform NTLM over HTTP authentication.
I'm not 100% sure it supports NTLM Authentication but have you investigated the connection:didReceiveAuthenticationChallenge method on the NSUrlConnection?