1

I'm trying to connect to the Expedia Api. With this they have an api key and id.

I was using jsonp with this but there is a bug in there causing problems. The other thing is my api key is exposed in the javascript.

So now I have to find another way. I am now requesting json but of course I can't get cross domain with it so I have found a php proxy. My app is now reliant on php (this is ok though). When I access the php proxy I now get authentication errors. I have tried a different endpoint on a different site and the script works.

So therefore I cannot access this API.

There seems to be very little information, tutorials and scripts out there on how to make an api cross site, php proxies or authentication. I thought with the amount of sites now reliant on this type of technology there might be something.

How can I make a php proxy and return this data back to angular? How can I safely hide my api key?

1 Answer 1

1

Have all of your API keys etc in a PHP file on your server. In that PHP file you need to curl to the API. Then have your PHP script return a json_encode() of whatever their API returns. That way no one sees your API deets.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok that makes sense..How can I complete the round trip by getting it back to Angular?
$http.post('/url/to/your/script.php', data) .then(function(s,r){ console.log(r.data); }); r.data will contain the response from your php script (which will echo out the response from the API)
Great thanks got that now. But my php response is now blank or it contains html. How can I return the json object now from the php file? it outputs as a variable $response = json_decode(curl_exec($ch));
$response = curl_exec($ch); echo $response;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.