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)
Related
i'm trying to add Google map to my app in map view and i want to put features like the one that in whatsapp. By providing the near places , search bar and share my current location.
Can any body help me and tell me if there is something i need to buy or request from Google or anywhere?
Initially, to get the map running, you can follow the steps shown in this page
With Google Places API you can search for nearby places in a given position. Or you can search for locations based on a string.
To get your current location, you can see how to do it here.
You dont have to buy anything. Although, Google API has limitations of access. For example, The Google Places only allow you to do 1,000 requests a day.
The Google Maps SDK for iOS do not limit the request.
Here is a snippet of a code of mine to access the Google Places API.
NSString * key = #"PUT YOUR KEY HERE";
NSString * html_msg = [msg stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
NSString * address = [NSString stringWithFormat: #"https://maps.googleapis.com/maps/api/place/textsearch/json?sensor=false&key=%#&query=%#", key, html_msg];
//Create URL and Request
NSURL * url = [NSURL URLWithString:address];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
NSURLResponse * response;
NSError * error = nil;
//Send Request
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error == nil) {
//Parse JSON to Dictionary
NSDictionary * json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
//Get the lat/lng of the first result
[json[#"results"][0][#"geometry"][#"location"][#"lat"] doubleValue];
[json[#"results"][0][#"geometry"][#"location"][#"lng"] doubleValue];
}
I'm not sure what features are included in whatsapp, but a google search tells me that there is a Google Maps SDK, with features that should allow you to create a "highly interactive" app. It doesn't seem to cost anything, but you do need to credit Google. Here's the link to their website: https://developers.google.com/maps/documentation/ios/
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 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.
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.
I want to have the user enter a keyword in my app and then search google for this keyword, perform some logic on the results and display a final conclusion to the user.
Is this possible? How do I perform the search on google from my app? What is the format of the reply? If anybody has some code samples for this, they would be greatly appreciated.
Thanks,
A RESTful search request to Google AJAX returns a response in JSON format.
You can issue the request with ASIHTTPRequest and parse the JSON-formatted response on an iPhone with json-framework.
For example, to create and submit a search request that is based on the example on the Google AJAX page, you could use ASIHTTPRequest's -requestWithURL and -startSynchronous methods:
NSURL *searchURL = [NSURL URLWithString:#"http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Paris%20Hilton"];
ASIHTTPRequest *googleRequest = [ASIHTTPRequest requestWithURL:searchURL];
[googleRequest addRequestHeader:#"Referer" value:[self deviceIPAddress]];
[googleRequest startSynchronous];
You would build the NSURL instance based on your search terms, escaping the request parameters.
If I followed Google's example to the letter, I would also add an API key to this URL. Google asks that you use an API key for searches, but apparently it is not required. You can sign up for an API key here.
There are also asynchronous request methods which are detailed in the ASIHTTPRequest documentation. You would use those to keep the iPhone UI from getting tied up while the search request is made.
Once you have Google's JSON-formatted response in hand, you can use the json-framework SBJSON parser object to parse the response into an NSDictionary object:
NSError *requestError = [googleRequest error];
if (!requestError) {
SBJSON *jsonParser = [[SBJSON alloc] init];
NSString *googleResponse = [googleRequest responseString];
NSDictionary *searchResults = [jsonParser objectWithString:googleResponse error:nil];
[jsonParser release];
}
You should also specify the referer IP address in the request header, which in this case would be the local IP address of the iPhone, e.g.:
- (NSString *) deviceIPAddress {
char iphoneIP[255];
strcpy(iphoneIP,"127.0.0.1"); // if everything fails
NSHost *myHost = [NSHost currentHost];
if (myHost) {
NSString *address = [myHost address];
if (address)
strcpy(iphoneIP, [address cStringUsingEncoding:NSUTF8StringEncoding]);
}
return [NSString stringWithFormat:#"%s",iphoneIP];
}