There is a REST API which I want to access and use the GET Method to get the data from xml and store it into MySQL. I thought to give PHP curl a try to request the data from API and setup a cronjob for the script run automatically on the given days. The problem is that the feed is not allowed to be accessed through browser. What other ways are there to get the data and store into mysql?
I used httpful client by nate good to solve this issue. Hope it helps other as well.
Related
I think it is inefficient to do a request on each page visit to collect the information. I would like to know what the theory of best practises are regarding to working with data that is received from an API.
Should the data be stored in my own database or should I just make a call to the API every time?
As example if I would use Strava to get my running results. Should I just use the result directly from the API or should I store these in a database. And than check after a certain period if there are new or updated results and update my database accordingly?
I have read some articles about RESTful API's but they only give information about how to get, delete, update the data etc.
It depends on what you are using it for...
If the information is likely not to change and is likely to be reaccessed on your site then store it.
Otherwise just get it from the API, it will always be up to date and it's less code to write if you don't have to store it.
If you are storing it and you know what information you are likely to require you could retrieve in the background at set-intervals.
You can also look at other factors when making your judgement, such as the speed of the API or if you have a API call limit.
You are probably not finding an definitive answer as there isn't one, but I hope this clarifies this for you =]
I don't know of Strava or whatever API you will use.
In my case, generally in applications there is a need to keep track of what have been exchanged with an external system, for example to give proof that the data has been read or written.
For this, usually there is something kept in the local database, and usually it does not have to be the track of the complete data exchange.
Okey so I am building a spotify app and I will need access to my MySQL database in this app both getting and inserting data to it, now spotify don't support PHP witch I would normally use for this so how do I work around this? I have no idea how to do this without using PHP.
Spotify API uses JavaScript and you can use for example jQuery framework with it. Just save
jquery.js to your addon-folder and include it in your script. Then you can use $.post() and others to save/retrieve data from your external server.
I have spent the past three days researching this... but Im still stuck.
I have a service provider that offers me a REST api. I need to:
Get the data from his api
Assign the data to variables in php
Write the data to my localhost sql database.
All that's required is the API KEY which has been provided to me.
Please could someone explain to me what method I should use to call and store the data in php.
Writing to the Database and handling the data once in php format is not a problem.
Thanks in advance
Since you want to consume a webservice you would have to make HTTP request using PHP.
There is many ways to do that but the most used(IMHO) is cURL. cURL function would allow you to easily make HTTP request and consume data from the webservice.
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 got a couple of affiliate sites and would like to bring together the earnings reports from several Amazon sites into one place, for easier viewing and analysis.
I get the impression that cURL can be used to get external webpage content, which I could then scrape to obtain the necessary info. However, I've hit a wall in trying to log in to the Associates reports using cURL.
Has anyone done this and do you have any advice?
I am working on an open-source project called PHP-OARA it's allows you to get your data from the different networks, it's part of the AffJet Project.
We have solved the problem with Amazon(it wasn't easy) and a PHP class is available to get your data from your associate account.If you like it you can even co-operate to do it better.
I hope it helps!
You can do this, but youll need to make use of cookies with curl: http://www.electrictoolbox.com/php-curl-cookies/ But id be willing to bet some cash that Amazon offers an API to get the data you want, although the last time i dealt with their web services it was a nightmare but proably because i was using the PHP SOAP extension and Amazon SOAP API.