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];`
Related
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)
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];
I have a UIWebView in my application where I 'm loading the facebook profile of my application. I am using facebook's single sign on SDK(Graph API). And I logged in into facebook in the Safari in background using my application. But When I try loadmy game profile in my application web view still I could see "Log In" and "Sign Up" buttons.
I tried setting cookies, main document URL and relative URL too but no use.
I am adding here my code too here,
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/myapp" relativeToURL:[NSURL URLWithString:#"http://login.facebook.com"]];
NSMutableURLRequest *request = nil;
if(url)
request = [NSMutableURLRequest requestWithURL:url];
NSArray * availableCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:#"http://login.facebook.com"]];
NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:availableCookies];
if(request)
{
[request setHTTPShouldHandleCookies:YES];
[request setMainDocumentURL:[NSURL URLWithString:#"http://login.facebook.com"]];
[request setAllHTTPHeaderFields:headers];//login.facebook.com
[mWebView loadRequest:request];
}
You may be running into the situation I describe in the answer on this page:
Facebook iOS SDK not storing cookies for access
i am implementing a facebook application , i have used Graph Api and have successfully logged into facebook and got the friend list with the id in UITableView, now i have one string, how should i post on friend wall, Suppose if i click on any of my friend in UITableView, a message should be post,plz help me
EDIT: Code
NSString *urlString = [NSString stringWithFormat:#"graph.facebook.com/%#/feed",key];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *newRequest = [ASIFormDataRequest requestWithURL:url];
[newRequest setPostValue:#"I'm inviting you to see download the OGC app" forKey:#"message"];
[newRequest setPostValue:fbGraph forKey:#"access_token"];
[newRequest setDidFinishSelector:#selector(postToWallFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
i am implementing this in function when clicked on tableview where key is id number for the friends name clicked in and in other function
NSString *responseString = [request responseString];
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *postId = [responseJSON objectForKey:#"id"];
NSLog(#"Post id is: %#", postId);
but i am getting the post id nil plz help me
Are you using the Facebook iOS SDK?
Assuming you are, use requestWithGraphPath e.g.-
[_facebook requestWithGraphPath:#"uid/feed"
andParams:[NSMutableDictionary dictionaryWithObject:#"Post on wall" forKey:#"message"]
andHTTPMethod:#"POST"
andDelegate:self];
Where uid is the user id of the user, naturally.
You'll need to make sure you have the relevant permissions when signing in to Facebook and handle the delegate call back to test for success.
If you're not using the SDK, you can do a similar thing with the Graph API directly, perhaps using your own NSURLConnection's or a third party library like ASIHTTPRequest. The SDK is pretty good and straightforward to use mind.
HI.. I have to show directions between two coordinates. I'd like to open Maps app, passing the start and end coordinates from my code.
I don't want to open it in the Google maps, which opens in browser(Safari). I tried that method. That was working perfect.
NSString* urlStr = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", s_lat, s_long, d_lat, d_long];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlStr]];
But, I want to open iPhone Maps app. How can i do this? Is this possible? Any help will be appreciated.
Try it on a real device. I'm using the same code and it opens Safari at the simulator and iPhone Maps at the device.
Hey Simon the method you are using is
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlStr]];
will only open safari.So there is no chance that with open url you would open a diiferent thing.You can use the UIWebView for this and then load the webview with the url.I think that would be the simple thing like this
views=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[views setBackgroundColor:[UIColor lightGrayColor]];
NSString* urlStr = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", s_lat, s_long, d_lat, d_long];
NSURL *url=[NSURL URLWithString:urlStr];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
//[views loadHTMLString:googlePage baseURL:requestURL];
[views loadRequest:req];
self.view=views;
And if you even don't want to use this then then you can use the MapKit provided in your XCode Frameworks.Hope this would help you.