I am new to api development, so don't know whether this is feasible or not.
I have a website(http://www.mysite.com/) which consists of data and i need to develop an api or somehow use this site's data to use it in another websites.
My requirement is other external websites(http://www.externalwebsites.com) need to search the data from my main site (http://www.mysite.com/). http://www.externalwebsites.com/ will send search string to http://www.mysite.com/ and it will send back result and show them in http://www.externalwebsites.com/.
i need to use ajax calls in http://www.externalwebsites.com/ for searching data, so my question is
Is this whole process feasible ?
Sure, you can use JSONP, supported by default in libraries like jQuery.
http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getJSON_.28using_JSONP.29
A good way is to use SOAP web-service:
http://plutov.by/post/web_service_soap
REST: http://searchsoa.techtarget.com/definition/REST
SOAP: http://tr.wikipedia.org/wiki/SOAP
oAuth: http://oauth.net/2/ (this is used by popular sites like Facebook, Google, Yahoo, Twitter)
Related
I Developed a REST Service in Jax-RS, and I have some functions that use the POST method, like:
Auth_User()
Get_List()
Insert_Data(id,name,data)
I need to access these functions using PHP cURL. What I basically need is to work the functions from the PHP files, so that my REST Service can work like Facebook App development.
how can I do this using cURL?
You can use the CURL library with it's wide range of options to perform GET/POST/HEAD etc. requests that you would need to communicate with your REST server.
As for parsing data, you would have to take a look at either json_decode() if you get json objects back, or e.g. SimpleXml if you need to parse it as XML.
See this site here for a decent example of querying the yahoo REST api in php/curl:
http://developer.yahoo.com/php/tutorials/water_bug_tutorial-making_rest_request.html
There is no such thing as a REST server. The question you are asking is "How do I make an HTTP request from PHP?" What technology the server is implemented with is absolutely irrelevant. At least it should be!
I've done some googling around on this topic, but there seems to be only one option: the Dropbox official API. Is there no other way i could do some sort of JSON/PHP get_file_contents etc, when you get tweets from twitter you can use the user_timeline, is there no alternative for Dropbox people have come across. I just want something i can put a username and password into the PHP script and have it get the files (or am i dreaming and will have to use the API)
Check out the Dropbox PHP SDK it uses OAuth for validation which is the safest way.
You're dreaming and will have to use the API. This is exactly what API's are for, for programming applications to talk to applications. Specifically on the subject of authentication, there would be so many security issues with just having a user/pass in your code it's not even funny. Things like OAuth and other API authentication methods exist to make this kind of thing safer and saner. Sort of like lighting a campfire in a firepit instead of the middle of a dry grassland.
There are libraries like the one fire mentions that can wrap the API and make it easier to access from your language, but you need to play by the rulebook here. I know it sounds daunting but your application will be the better for doing it right.
You could also use the hosting service KISSR which would allow you to host your entire site out of Dropbox. This would be simpler than using the API but you wouldn't be able to use PHP.
it is not that much of a odd question that has been asked. as if you are using two hosting services one of them for just hosting images the other is for interaction events, done gazillions of time, some servers use term 'content/image leeching', hard to differenciate legit useage. however thats what consumer is asking/requesting, funny answers
I want to write a PHP script that performs a routine task in a web app I use. I am trying to figure out the easiest way to submit a form, click a link, and get some information. What's the easiest way to do this (keeping the session open, etc.).
Javascript would be a better solution than PHP. You can use it in tandem with PHP to submit a form that references the same page, ie. <form method='index.php' action='post'>
If method is GET then you ought to be able to work it out form the URLs of a few real world attempts.
It POST then you are probably SOL unless it's your own web page./app and you know what $_POST it expects ... unless you find a tool to snoop your HTTP traffic and get the POST info from observing a few real wrold examples.
You can use CURL in PHP to simulate submitting data, clicked links, etc., I suppose, but a client-side scripting language like Javascript--as opposed to a server-side language like PHP--is more suited to what you're describing. I'd need more info to give you a specific example.
You will not be able directly emulate those events in PHP as web apps use Javascript on the client side and PHP is a different language and operates on the server side.
Firstly, I would see if there is an open API available for the web app you're wondering about, e.g. Gmail: http://code.google.com/apis/gmail/ . Not all APIs can do what the web app can do, so you'll need to check the documentation to make sure the API does what you want and has an easy way to interface with PHP.
The other option is to essentially reverse engineer how the web app communicates with it's server. Most all web apps operate by sending POST or GET HTTP data in some sort of serialized format like XML, JSON or text. You can use something like the Firebug add-on for Firefox to view POST/GET data. If you know what the server sends to the client and what the client sends to the server, you can essentially write a script using something like CURL to emulate the client in PHP instead of JavaScript. This would take quite a bit of work and probably involves a lot of trail & error.
Is it possible for a web page using Javascript to get data from another website? In my case I want to get it for calculations and graphing a chart. But I'm not sure if this is possible or not due to security concerns. If it is considered a no no but there is a work around I would appreciate being told the work around. I don't want to have to gather this information on the server side if possible.
Any and all help is appreciated.
Learn about JSONP format and cross-site requests (http://en.wikipedia.org/wiki/JSON#JSONP).
You may need to use the "PHP-proxy" script at your server side which will get the information from the websites and provide it to yours Javascript.
The only reliable way is to let "your" webserver act as a proxy. In PHP you can use curl() to fire a HTTP request to an external site and then just echo the response.
You can't pull data from another server due to the same origin policy. You can do some tricks to get around it, such as putting the URL in a <script> tag, but in your case it wouldn't work for just parsing HTML.
Use simple_dom_html, to parse your data server side. it is much easier than doing it in JavaScript anyways.
A simple way you might be able to do this is to use an inline iframe. If the web page you are getting the data from has no headers, or you can isolate the data being pulled in (to say an image or SWF), this might work.
cross-domain javascript used to be impossible, using a (php-)proxy was a workaround for that.
jsonp changes this entirely, it allows to request javascript from another server (if it has an API that supports jsonp, a lot of the bigger webplayers like google, twitter, yahoo, ... do), specifying the callback-function in your code that needs to be triggered to act on the response.
the response in javascript will contain:
a call to a callback-function you defined
the actual payload as a javascript-object.
frameworks like jquery offer easy support for jsonp out of the box.
once you have the raw data you could tie into google chart tools to create graphs on the fly and insert them in your webapp.
Also worth considering is support for XMLHttpRequest Access Control which is support in some modern browsers.
If the service provider that you are trying to access via a web page has this set up, it is a very simple call to XMLHttpRequest and you will get access to the resources on that site without the need for JSONP (especially useful for requests that are not GET, i.e. POST, HEAD etc)
I am developing a script in php to manage my rapidshare accounts (for learning purposes), i wanted to know how can we login remotely and get accounts details on my site, something that api does, the details like traffic left, expiry date, etc.
Uncertain what exactly your question is, but it probably helps to take a look at the Rapidshare API. Additionally you probably want to make yourself familiar with the following functions/ components: fopen and curl to use the api/load the site. To get specific parameters out of the content I suggest using ereg or the xml functionality.
With PHP you could use either Curl, PHPSimpleHTMLDomParser, Snoopy, or phpQuery to grab the contents from the remote page. Be mindful that some websites require a user_agent, in which case you could setup one through ini_set prior to running your script.
You could use cURL to send HTTP requests from your script to the site. There are also ready-made solutions for PHP, such as Snoopy, which will let you do things like posting a form or scraping a page, without having to use cURL directly.
Since Rapidshare does not provide an API interface to their service, the only way is to use an HTML parser available for PHP, login with the script, and parse the values.
Update: Rapidshare does provide an API as merkuro has stated in his post.