I am trying to get an introduction to serving files to the iphone. I have watched tutorials on getting files from sites like Flickr and twitter. I need a tutorial to show me how to set up the site that is feeding that information. Most of those sites send you a json file. Can I just keep a dynamic file on a server using php?
PHP has some great json functions. See json_encode, which takes a PHP structure and converts it to a json string, and json_decode, which does the opposite. Make sure you set a Content-type: application/json header, echo the result of json_encode, and your iPhone app should be able to read it. Similarly, you can use json_decode to read JSON data that has been sent to your PHP script using GET or POST (preferably the latter).
All those sites use a web service to achieve the json response, depending on what you are using the ability to send back json responses might be built in to the services framework etc (.net for example), here is a question that talks about using .net to make a webservice iPhone interaction with ASP.NET WebService, im sure you can find many more out there
Found this tutorial once i got a better understanding of what i needed to do. http://davidwalsh.name/web-service-php-mysql-xml-json
Related
My API written in PHP returns JSON in an api used by a phone.
Depending on certain paramaters, the PHP file either returns the JSON itself or redirects to a different PHP file that returns similar JSON.
In a browser, the JSON returned directly from the starting file looks identical in form to the JSON returned after the redirect. However, the phone is not getting any JSON at all if there is a redirect.
This doesn't make sense to me but it's what I'm seeing. Is it possible for a redirect to mess up a JSON response?
For the record, here is what the JSON looks like in the browser:
{"comment":[{"response":"Hello World"}]}
Edit:
Apparently, redirects in restful APIs are somewhat frowned upon but possible, however, do you have to do something with a status code? This is unfamiliar territory for me.
JSON response redirect
Thanks for any ideas.
You can do redirects using 307 temporary and 308 permanently codes as stated in the IETF draft https://tools.ietf.org/id/draft-hunt-http-rest-redirect-00.html#rfc.section.2.1
Redirection is not the right tool in your case.
As I understand you‘re trying to delegate different endpoints to different files. You should have a look at request routing which happens server side, the client should not have to deal with this.
https://link.medium.com/Sdp3DyXTHX
https://symfony.com/doc/current/components/routing.html
https://www.php-fig.org/psr/psr-7/
Here's the documentation on how to implement Janrain engine in Android.
Example of server side response is here.
Quote: "As necessary create and return access tokens or session cookies in your endpoint's response.", I don't want to save data on session or cookies, I want to get just plain text to my app as response.
How can I do this?
Also I work with php, I don't really get ruby example.
There is some sample PHP code at https://github.com/janrain/Janrain-Sample-Code/blob/master/php/rpx-token-url.php that returns a block of JSON. You could customize this code to return the plain text response you're looking for.
Do I need to use JSON to transfer data from external PHP server to Phonegap iPhone app? Or can I use a $.get function to pull data from a PHP file?
Thank you for your help in advance,
No you don't, you can use any format you wish except for binary since it comes back as textual data available in jqXHR which is a superset of XMLHttpRequest, so you can retrieve its response.responseText property
http://api.jquery.com/jQuery.get/
The point to remember is that PHP is not in your app, it's on your server. You're calling a webservice to get some info, in essence, and no Apple does not put any restriction on this. I've created and released a hybrid app that pulls data from my webservice and displays it in app. No problems.
And you can use any format you want, XML or JSON being most popular
You can use $.get to retrieve json generated by your php file.
I believe $.get assumes a json response though.
I am creating a website that requires me to decode qr codes. I did my research and found out that php does not natively support decoding of qr codes. So, I decided to use the webservices that provide decoding of qr codes. I came across a good webservice, Zxing, which decodes the image submitted to it. The problem that I found was that I could not find enough documentation online with regards to the usage of the Zxing webservices, like how should the parameters be passed to the url of the webservice. The url that I am to access is, http://zxing.org/w/decode.jspx,
but then how should I consume this webservice using SOAP / XML-RPC in php.
I studied the result that is returned when I click on the "Submit" button, and its a simple text document.
Please, do give me guidance as to how should I consume the Zxing webservice, are there any online documentations?
Thanks.
It's not really documented as an API since it's not an API. You are not meant to integrate for use in your own service. It's a site I run as a free courtesy to end users on the web. It's OK to send a few requests at it, but for any significant volume, please run your own.
But the HTML is pretty much all the documentation you need: you can see what URL it posts to, and what parameters it sends. It's really just a POST of image content under parameter 'f', or a GET to the same URL with parameter 'u' specifying a URL to load.
The complete source code is at http://code.google.com/p/zxing, under zxingorg/. You probably want to run your own copy, so you can control it and modify it.
I am playing around with Objective-C and have been looking for a good how-to example to exchange data it and PHP. JSON? SOAP? If anyone knows of a well written example I could hack at, I would appreciate it.
When you say exchange data, do you mean over a network connection, between programs or through files?
If you are look to transfer the data over an internet connection (eg. your Objective-C program has/is a web server) then I would personally use JSON as this would allow your Objective-C program to communicate with a javascript web app in future if required as well as the simple php json_encode / json_decode functions.
I would personally say the same applies to other systems, but depending on how you expect this to work something like xml or SOAP may work better.
Edit:
JSON Framework for Objective-C on Google Code
PHP Manual for JSON (including links on to json_encode and json_decode) functions.