I am using google places api to get that place's photo but i am unable to locate "photo_reference" field in the returned JSON. Here is what i have done so far.
NSString *urlString = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/details/json?placeid=%#&key=%#",placeId,appKey];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
NSLog(#"Got Place Details");
NSDictionary *details = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSString *photo_reference = [[[[details valueForKey:#"result"] valueForKey:#"photos"] objectAtIndex:0] valueForKey:#"photo_reference"];
NSLog(#"");
NSString *urlString = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/photo?maxwidth=302&maxheight=275&photoreference=%#&key=%#",photo_reference,appKey];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(#"Inner Request");
if (!connectionError) {
}];
}
}];
Places API documentation says that photo_reference could either be found from "Place Search" or "Place Details" requests. I got it from none.
I requested place details using place_id but the json doesnt have any "photos" key.
Same issue here
https://stackoverflow.com/questions/28317739/places-api-dont-retrieve-photos-on-detailed-petition-since-yesterday
Something change since yesterday but I don't know what or why.
EDIT: Today it's working again, maybe some random error from google.
Related
I am trying to get the number of twitter followers in my iOS App.
I find some Documentation regarding this issue:
https://dev.twitter.com/rest/reference/get/users/lookup
This is the code I have so far:
NSString *apiURLString = [NSString stringWithFormat:#"https://api.twitter.com/1.1/users/lookup.json?screen_name=%#", #"barackobama"];
NSURL *apiURL = [NSURL URLWithString:apiURLString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:apiURL];
request.HTTPMethod = #"GET";
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
// ((NSHTTPURLResponse *)response).statusCode
NSLog(#"response = %#", response);
}];
However, I am pretty confused as how to send all the other parameters required for the request.
Thanks in advance!
This is my json Dictionary
{"pid":"14982","type":"intervention","uid":"10008","bookmark_g7l03":{"und":[{"value":"S:1","format":"null","safe_value":"S:1"}]}}
I need to pass the PUT request to the following URL
http://example.com/services/profiles/pid
Let us know how to pass the dictionary to Webservice URL in IOS
NSString *data = [NSString stringWithFormat:#"{\"pid\":\"%#\",\"type\":\"%#\",\"uid\":\"%#\",\"%#\":{\"und\":\[{\"value\":\"%#\",\"format\":\"null\",\"safe_value\":\"\%#\"}]}}",pid,type, uidNo,bkMarkStr,self.startString,self.startString];
NSURL *bkMrkUrl = [NSURL URLWithString:#"http://example.com/services/profiles/pid=14997"];
NSData *postData = [data dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *bkMrkReq = [[NSMutableURLRequest alloc]initWithURL:bkMrkUrl];
[bkMrkReq setHTTPMethod:#"PUT"];
[bkMrkReq setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[bkMrkReq setHTTPBody:postData];
[NSURLConnection sendAsynchronousRequest:bkMrkReq queue:[NSOperationQueue currentQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *txt = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(#"data....:%#",txt);
// handle response here
}];
Here, When i Print the text data
Output is: <?xml version="1.0" encoding="utf-8"?>
<result>CSRF validation failed</result>
What should i do with the data..
Here am updating the fields info in server.
You can try:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"http://example.com/services/profiles/pid"]];
[request setHTTPMethod:#"PUT"];
NSString *params = #"\{\"pid\" : \"14997\", \"type\" : \"intervention\", \"uid\" : \"10046\"}"; // The rest of your parmas here
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
// handle response here
}];
If you want to make the request synchronously instead you can use:
NSURLResponse *response;
NSError *error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
I need to get place_id from facebook for facebook checkin section.For that i am using following code.While requesting place id with access token sometines i get message as malformed access token,sometimes expired.
NSString *fbToken = [FBSession activeSession].accessTokenData.accessToken;
NSString *fbURL = [NSString stringWithFormat:#"https://graph.facebook.com/search?q=ritual&type=place¢er=9.952786,76.339828&distance=1000&access_token=%#",fbToken];
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#",fbURL, fbToken]];
NSLog(#"URL:%#",URL);
NSURLRequest *placeRequest = [NSURLRequest requestWithURL:URL];
//Send the request
[NSURLConnection sendAsynchronousRequest:placeRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if (!connectionError) {
NSDictionary *Data = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(#"data = %#"Data);
}
}];
I'm just doing exactly what I do for HTTP requests:
NSString *urlStrig = [NSString stringWithFormat:#"https://mysite.com/search.json?param1=10¶m2=String¶m3=20"];
NSURL *url = [NSURL URLWithString:urlStrig];
NSOperationQueue *queue = [NSOperationQueue new];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:Timeout];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(#"URL:%#\nResponse: %#\nStatusCode: %i\nError: %#", url, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding], ((NSHTTPURLResponse *)response).statusCode, error);
}];
But all I got is a 403 status code everytime. Testing it via curl in the terminal works fine.
Is there any problem between HTTPS and NSURLConnection?
i am trying to add like button on my application in ios . when i hit url in graph api explorer it works fine, and give me response true. but when i hit this in my code nothing happened
(void)likeFacebookPost:(NSString*)likeID
{
NSString *theWholeUrl = [NSURL URLWithString:[NSString stringWithFormat:
#"%#/%#/likes&access_token=%#",
GRAPH_API_BASEURL,likeID,
[_facebookToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:#"POST"];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];
NSLog(#"responseData: %#", content);
}