I've the following problem:
I'm parsing an XML File from Flickr API http://api.flickr.com/services/feeds/photos_public.gne?tags= with a specific tag, provided by the user before.
Then I get a XML file where in each
<entry> item a line exists like
<link rel="enclosure" type="image/jpeg" href="IMAGEURL">
Is there an easy way to parse this line of code with NSXMLParser? Or should I use another way to get the IMAGEURL?
You should be able to use the delegate method parser:didStartElement:namespaceURI:qualifiedName:attributes: to get that info. The attributes are available in the attributesDict. So you can get the IMAGEURL using,
NSString * imageURLString = [attributesDict objectForKey:#"href"];
when elementName is "link".
I have tried this as well and it doesn't work anymore because the html is not well formed xml. This is the error I got: NSXMLParserErrorDomain Code=111
Now using the Flickr API and it works like a charm.
You have to create an API key: https://www.flickr.com/services/apps/create/
Related
https://github.com/microsoftgraph/microsoft-graph-docs/issues/2624
I am experience the issue as the above.
I am trying to save the content of a page with a reference to an image by calling https://graph.microsoft.com/v1.0/users/{userId}/onenote/pages/{pageId}/content?preAuthenticated=true
Per this - Downloading one note page with image content as HTML
By appending "?preAuthenticated=true" when you do the fetch, it will make the image public.
But when I tried to render the html, it's giving me "Failed to load resource: the server responded with a status of 401 (Unauthorized)".
It appears that something is wrong with the official document: Get OneNote content and structure with Microsoft Graph.
We can see that the service root URL is https://graph.microsoft.com/{version}/{location}/onenote/.
But in any of the samples on this page, the URL is still https://www.onenote.com/api/v1.0/me/notes.
Currently, when you add ?preAuthenticated=true you will get such a URL for a image on this page:
https://graph.microsoft.com/v1.0/users('{userID}')/onenote/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
But when you try to access it in a browser, you will get 401 error Access token is empty.
A workaround is to modify the URL to:
https://www.onenote.com/api/v1.0/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
Then you will get the image.
https://github.com/microsoftgraph/microsoft-graph-docs/pull/4339/files
I think they removed the support for it.
Bit of off topic, but I figured out how to get the image to render.
https://learn.microsoft.com/en-us/graph/api/resource-get?view=graph-rest-1.0&tabs=http
When you call /onenote/pages/{id}/content, the image has a reference to a source like this
src="https://graph.microsoft.com/v1.0/users({userId})/onenote/resources/{resourceId}/$value" along with data-src-type="image/jpeg"
do a get request to this endpoint and you'll the image binary, convert the binary to base64, and then just render the html by replacing the src with base64.
I'm working on a project, and I'm completely stuck.
I get the user's location using CLLocation and am able to get the place name using CLGeocoder, and using this I've constructed a URL to search the Google Places Web API.
My question is, how can I actually complete the search and return the top place result's phone number? Any help would be much appreciated!
let url: URL = URL(fileURLWithPath: "https://maps.googleapis.com/maps/api/place/textsearch/json?query=taxi+" + placeMark.locality!+"&key=" + self.GAPIKEY)
This is the URL I've come up in case that helps
The first thing you need to do is an HTTP GET on the URL to get the API results. Consult the following SO question for various ways to do that:
How to make an HTTP request in Swift?
The data returned will be a JSON document in the format described in the Google Places API Docs. Look for the formatted_phone_number and/or international_phone_number fields. See Working with JSON in Swift for how to parse the JSON string.
I am developing an iPhone application that is using an API to find recipes from http://www.recipepuppy.com/about/api/.
There are three parameters that must be put into return results. There are i,q, and p, Where i are the ingredients, q in a normal search query and p is the page #. I am able to specifically add these parameters and then load the results into a table view in Xcode.
I also want to implement a search that allows the users to search for recipes based on whatever they feel like and return the results. Could someone point me in the correct direction on how to do this. I know I will have to take what ever the user inputs and place it into a string but how do I implement that string into the parameters of the URL?
To answer your question:
I know I will have to take what ever the user inputs and place it into a string but how do I implement that string into the parameters of the URL?
You can use the stringWithFormat method of NSString. For example:
NSString *ingredients = #"ingredients";
NSString *query = #"soups";
NSString *page = #"1";
NSString *url = [NSString stringWithFormat:#"http://www.recipepuppy.com/api/?i=%#&q=%#&p=%#",ingredients,query,page];
Before using this URL, it's recommended that you URL encode it.
NSString *encodedURL = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Now that you have your URL, just start a connection to the web (NSURLConnection, AFNetworking, the choice is yours), parse the data returned, and load that into an array to display in the table view.
To build a solid app that involves JSON communication over the network, you can use the JSONModel library. It provides you with data models, and takes care of sending and receiving JSON forth and back to your API service.
You can have a look at the GitHub page:
https://github.com/icanzilb/JSONModel/
Or also to this example on how to use the YouTube JSON API with JSONModel:
http://www.touch-code-magazine.com/how-to-make-a-youtube-app-using-mgbox-and-jsonmodel/
On the GitHub page there are more code samples. Good luck :)
(Disclosure: I'm JSONModel's author)
I'd use AFNetworking for all your network requests:
https://github.com/AFNetworking/AFNetworking
To make the request just construct an NSString and send it off
[NSString stringWithFormat:#"http://www.recipepuppy.com/api/?i=%#&q=%#&p=%d", self.ingredients, self.query, self.page]
As per requirement I need to post user profile details like user name, first name, last name and profile picture from IPhone device. How can we send these details including “profile picture” together? Do I need to send these details as a JSON object? So I need to convert the image as byte array. Right?
If you can provide any IPhone code snippet then it would be better.
Also if possible please provide the code for WCF Rest service Part.
Thanks in advance.
To send data to the server in JSON format:
ADD:
JSON.h (Header)
JSON.m (Implementation)
Use
https://github.com/stig/json-framework/download
To convert your profile details, you can refer following sample
NSMutableDictionary *jsonEncode = [NSMutableDictionary dictionary];
[jsonEncode setValue:#"" forKey:#""];
NSString *jsonString = [jsonEncode JSONString];
To send Image to server you need to convert image into Base64 format.
Refer link below:
UIImage to base64 String Encoding
There are a bunch of tutorials online about how to use xmlparsers or what not to bring an entire twitter feed into a UITableView. Thats not what I need. I only want ONE tweet. The most recent twitter update.
So, would some of you geniuses please show me in detail how to get my last (most recent) TWEET into an NSString in my iPhone app?
In short: exactly the same as all those tutorials that you've read except you pass the count parameter to the statuses/user_timeline REST method.
Ohh, this is complicated, not so easy, I show you the steps:
Make the request to the api (synchronous or asynchonous)
Handle the Authentication Challenge for authenticated request
Get the data, call the parse method of the parser
Handle the delegation methods of the nsxmlparser
Manually handle the DidStartElement, DidFoundCharacters, DidEndElement to get the first status you want, assign the string value to a variable when it founds the characters.
That's all you need to do ;)
Good luck.