No result from google API PHP - php

I want to get the distance from one point to another using the google API, but I'm having some issues.
My API link is:
http://maps.googleapis.com/maps/api/directions/json?origin=55.061744,9.429565&destination=Opnæsgård,%20Hørsholm,%20Denmark&alternatives=true&sensor=false
If I access this link from the browser, I get the correct distance however; when I try to access the exact same URL from my php script, I get an error.
My php script:
<?php
print_r(file_get_contents('http://maps.googleapis.com/maps/api/directions/json?origin=55.061744,9.429565&destination=Opnæsgård,%20Hørsholm,%20Denmark&alternatives=true&sensor=false'));
?>
Output from php script:
{ "routes" : [], "status" : "NOT_FOUND" }
As you can see, I'm getting two different results with the same URL, and I have no idea why.
I have also tried using CURL in the php script without any luck.
I hope you can help me
//Mikkel

Related

Blank results on json parse on https api calling using php and MAMP

I´m trying a very simple php script which is about calling a json data through api calling on a online https link using MAMP.
However if I use the following code I have blank results:
<?php
$cnmkt = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
$json = file_get_contents($cnmkt);
$fgc = json_decode($json,true);
echo $fgc[1]['percent_change_7d'];
?>
But if i copy/paste the content of the https link into a test.json file locally, substituting the https link with the test.json file on $cnmkt variable, the same exact script works properly.
I know i´m missing something very obvious, if someone could help me that would be very much appreciated, thanks.
Stefano
The script is working fine. I get an expected result of 4.63
Disable your AV/firewall and check again.

How to send BatchRequest?

It's been first time when I am going to use an APi for working with a Web Application. Google Analytics Dev-Guides show a Basic sample which is shown below.
I am TOTALLY UNAWARE of how to execute it..Okay, I would replace ViewId with mine.. Do I have to save it in .php Format ? or what ? anybody here can tell me step by step procedure
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests":
[
{
"viewId": "XXXX",
"dateRanges": [{"startDate": "2014-11-01", "endDate": "2014-11-30"}],
"metrics": [{"expression": "ga:users"}]
}
]
}
Go though the steps in the Hello Analytics API for JavaScript
create a google developer project
get your API credentials and a View ID you own.
load the webpage.
If you get stuck on a particular step come back and ask for help.

Webex: How to list hosts meetings

Using PHP I need to get a list of company webex meetings and show them on web page
I tried the code on this page: https://developer.cisco.com/site/webex-developer/develop-test/xml-api/sample-code/
But that failed.
<serv:header>
<serv:response>
<serv:result>FAILURE</serv:result>
<serv:reason>Failed to get SiteUrl</serv:reason>
<serv:gsbStatus>PRIMARY</serv:gsbStatus>
<serv:exceptionID>010000</serv:exceptionID>
</serv:response>
</serv:header>
<serv:body>
Error message was that it could not find the SiteURL. The siteurl I was using is companyname.webex.com - when I put that url into browser, it goes to our webex page, so it seems to be correct.
I found this: http://joshuamcginnis.com/webex/ and tried it (using real credentials), but it gives a 500 error and I have no access to logs.
Both of these examples are very old and I am struggling to find up-to-date examples.
If I put https://company.webex.com/WBXService/XMLService into browser, I get a success message
Can anyone suggest how to do this in either PHP or javascript
According to the PHP example in the link, you must be using something like:
<securityContext>
<webExID>YourCiscoUsername#example.com</webExID>
<password>YourCiscoPassword</password>
<siteID>243585</siteID>
<partnerID>g0webx!</partnerID>
</securityContext>
Try using the "siteName" instead of "siteID", like the following:
<securityContext>
<webExID>YourCiscoUsername#example.com</webExID>
<password>YourCiscoPassword</password>
<siteName>go</siteName>
<partnerID>g0webx!</partnerID>
</securityContext>
You can use siteID or siteName indistinctly, but looks like that siteID isn't working for that demo site right now. Their Java and .Net examples are using siteName.
Now, you have to use "go" in siteName if you are making the request to https://go.webex.com/WBXService/XMLService
But you must use "apidemoeu" if you are making the request to
https://apidemoeu.webex.com/WBXService/XMLService
They both appear to be demo sites.
And effectively "Failed to get SiteUrl" is the error returned if the value passed in either siteName or siteID doesn't correspond to an existing site.

Retrieving M3U8 via PHP vs. via Website gives different session variables

I'm trying to scrape a website (www.glturk.com).
When I run the below link via a browser:
http://www.glturk.com/ajax.aspx?stream=live&type=free&ppoint=ATVTurkiye_LR
I get the following response:
http://38.117.88.248:7777/ATVTurkiye_LR.m3u8?user=sglsxxdewfiduaqygnbfnqwcuc55&session=e0e8f5e6dbfb83be9e4f1155454b43d14130b7e79528a6fbe8dcb832c9f2cef0fbecdaf0092c93ab9826978c8d46626c20ba4293a32569e6e7cfbbd9d61c69ad
The above M3U8 link works perfectly in that instance.
But, if I try to replicate this via a PHP file, I get a very similar result, but that m3u8 link does not work?!
<?php
$channelURL= 'http://www.glturk.com/ajax.aspx?stream=live&type=free&ppoint=ATVTurkiye_LR';
$actualLink = file_get_contents($channelURL, TRUE);
echo $actualLink;
?>
The result I get is:
http://38.117.88.249:7777/ATVTurkiye_LR.m3u8?user=sglspoqmpdi2tltn0lynorytlnvi&session=08e5fd64dca2f17d9e4f1155454b43d136fa14cb989a57687b29865e85d60962253ac665a78595d7c5529895b22236c2f32018226b4a15e9b8327f16597d3505
This m3u8 does not work though, I can't understand why.
Working (via direct link through browser):
http://38.117.88.248:7777/ATVTurkiye_LR.m3u8?user=sglsxxdewfiduaqygnbfnqwcuc55&session=e0e8f5e6dbfb83be9e4f1155454b43d14130b7e79528a6fbe8dcb832c9f2cef0fbecdaf0092c93ab9826978c8d46626c20ba4293a32569e6e7cfbbd9d61c69ad
Not Working (via PHP):
http://38.117.88.249:7777/ATVTurkiye_LR.m3u8?user=sglspoqmpdi2tltn0lynorytlnvi&session=08e5fd64dca2f17d9e4f1155454b43d136fa14cb989a57687b29865e85d60962253ac665a78595d7c5529895b22236c2f32018226b4a15e9b8327f16597d3505
Any advise would be appreciated :) Thank you!

POST with curl gives correct output but with AJAX gives an error

I am quite frustrated with a very weird issue. I am trying to do a very simple thing here. I would like to post a form to an endpoint. I tried using the following command:
curl -d "Contact=Aditya&address1=1510 E. 9th Street&address2=Apt. 111&city=Tucson&state=AZ&zip=85719&Phone1=5207849817&Phone2=1237849812&email=aditya15417#yahoo.com&key2=09 New Lead&key5=AmpushU&uhsgradyr=1950&uhighlevel=AA&ucourseint=BA Internet Mktg&uCampaignID=Herlambang&utextperm=YES&uleaddate=20110910&uleadtime=19:18 PST" http://dev.degreeamerica.com/candidate_test.php
And yes it succeeds just fine, however when I try it via the site it gives me an error. Can someone tell me what I did wrong? The parameter I have on the curl is just something I copy and paste from firebug POST request, so the parameter is all the same.
Is there something wrong with me doing the AJAX?
You can't receive the results of a cross-domain post like that. Your page is on adityaherlambang.com, but you're posting to degreeamerica.com, so you can't get the results
One solution is to use a server-side proxy on adityaherlambang.com, and post using libcurl to degreeamerica.com, while returning whatever kind of status you want to your own site's JavaScript.

Categories