Janrain server side response to Android app - php

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.

Related

PHP Is a redirect in API that returns JSON okay?

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/

Android - Registration/Login Form with mysql.php

I am new to android. I have searched so far so many websites to begin login / registration form using php , mysql in android i have got no proper sites with output. As a beginner level i need to know is there any sites which has proper output or else guys can u help me with complete coding. I would be so gratefull if i am pleased with complete coding.
Thanks in advance.
Your question Is not all that clear. I think of two ways you can do what you are looking for.
Build a real android app and pass the data via XML.
You create a webview (basically you are displaying a website though the app)
In which case you use php like you would a normal site and the front end is very mobile friendly.
So either way you go you need to google "php login tutorial"
You must learn about standard connection ways of this two platforms like XML and JSON.
I recommend you to use JSON, but how?
You must use HTTPRequest functions in Android to POST your requests then from other side in PHP you must receive them in your PHP file easily with $_POST array and use it to check login data and reply the result to Android by using JSON functions like echo json_encode() and get them in Android again;
$username = $_POST("username");
$upass = $_POST("password");
$modelResult = User::model()->login($username, $upass); // return an array
echo json_encode($result); //echo array to android

Passing Information Between a Database through JSON

I need to display information from an SQL database which resides on a server, to a remote webworks mobile device. I am extremely new to passing information from a server so bear with me. My normal understanding is that I would have an HTML file that accesses a php script which then itself connects to the database and displays the information.
However, in webworks the HTML/Javascript files reside on the device and are separated from any php file so I need a method to communicate to get the data from the database. I have looked through JSON and read all the tutorials on w3schools and I understand the syntax but I don't understand how to use it. How could it connect to a database? My aim is to simply display the table entries on a mobile device app running HTML5 webworks. Again I am very new to this so any explanation would be very helpful.
Chances are, you should get a book. This is not something that can be explained in detail in a short answer on this site.
in summary however, you can either
1) send requests to your php script by submitting a form on an html page, which will load a new page filled with whatever PHP sends back. in this case you do not need to use JSON at all as PHP would be returning a full html page.
2) you can use AJAX. AJAX is a javascript method of sending requests to the server (PHP), and getting a response without ever loading a new page. you would use AJAX to send a request to the php page, the php page would access the database and send back a response, the javascript would then take the response and do whatever it needs with it. the response data is usually formatted in a JSON format, because PHP can easily create JSON, and javascript can easily decode JSON once it receives it as a response. to make using AJAX simpler, you may want to look in to using jQuery, a javascript library which can simplify the process.

Using Zxing online qr code decoder using php

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.

Serving a json file for IPHONE app

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

Categories