I am facing very weird issue, google distance matrix api is working on all server but not working on inmotion server. Could anyone help me to sort this issue.
I am using php and below is the standard code. This is not printing anything while same code is working everywhere. I tried with specific ip, specefic domain setting in google console api but did not find anything working on this server
$data = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&key=your_key");
$data = json_decode($data, TRUE);
print_r($data);
Related
I have this weird problem. It works fine on my local machine. But the problem happens when I upload this project on the live server (in a sub-domain for testing purposes). GitHub Repository
The project has one Model (other than User), "Post"
The project has one route and one API endpoint. Initially, I should get the same results from both the web route and API endpoint. The problem is when I delete a post from the web, the API result still shows that deleted post. The API returns updated results after 20-30 minutes.
Very strange issue.
If anyone knows anything about such an issue, please help me out.
I am using Livewire
App\Http\Livewire\Posts.php
public function render()
{
$posts = DB::table('posts')
->select(DB::raw("
posts.id AS id,
posts.title AS title,
posts.category AS category,
posts.author AS author
"))
->orderBy('posts.category')
->get();
$data = [
'posts' => $posts
];
return view('livewire.posts', $data);
}
api.php
Route::get('posts', function() {
$posts = DB::table('posts')
->select(DB::raw("
posts.id AS id,
posts.title AS title,
posts.category AS category,
posts.author AS author
"))
->orderBy('posts.category');
return response()->json($posts->get(), 200);
});
Actually, it was my fault. I did try
php artisan cache:clear
php artisan optimize:clear
And it did not work since there was a caching configuration in Nginx.
You know, when you are a noob at server management and end up using a nice and ready solution like myvestacp, you may end up making silly mistakes like this.
The way myvestacp is configured, it utilizes a combination of Apache and Nginx (as proxy). Without knowing the outcome, I had set the Nginx proxy as "caching" instead of "hosting-public". This is why the API result would get cached and only update after some time.
I did not face any issues so far because I did not use API before.
But thank you anyway for your time and effort.
I'm trying to get a local api and local website(consumer of api) to work together for last two days but no joy.
Local Api: apishop.test
Local Consumer: frontendflex.test
When i connect to a live api (like fakestoreapi.com) it works fine from Local Consumer website. Both my own local api and the fakestoreapi produce valid json on screen
I have tried various ways to communicate with the local api that dont work.
$res=json_decode(file_get_contents('http://apishop.test/products/' . $request->product)
error..
file_get_contents(https://apishop.test/products/2): Failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
$res = Http::acceptJson()->get('http://apishop.test/products/' . $request->product);
ErrorException
Undefined property: Illuminate\Http\Client\Response::$title (View: C:\xampp\htdocs\frontendflex\resources\views\shop\product.blade.php). This makes sense beacause if I dd($res) it is 500 internal server error like file_get_contents()
So to curl...
curl_setopt($handle, CURLOPT_URL, 'http://apishop.test/products/2');
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']??null);
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
//$res= json_decode(curl_exec($handle), true); //Attempt to read property "title" on null
//$res= curl_exec($handle); //Attempt to read property "title" on string
curl_close($handle);
But when I dd($res) it spews out crazy error data at which the top is....
Illuminate\Database\QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'frontendflex.products' doesn't exist (SQL: select * from products where products.id = 2 limit 1)
http://apishop.test/products/2
There is NO products table here, it is in api website. I'm running frontendflex.test here. So getting more curious, I deliberately caused an error in api website code and it picked it up on the consumer website frontendflex.test. What's going on here ?? Both websites are totally separated but under xampp. Head-banging for two days now. Any help appreciated
Well in desperation i created a brand new clean laravel project, just one controller and one route to access the api and it worked. So, I need to drill down as to what is happening with the other site. Mis-config somewhere.
Edit:
I discovered that for some reason if i access the consumer website (frontendflex.test) by php artisan:serve (http://127.0.0.1:8000/doda)it accesses the api site apishop.test no problem. Weird, but not wonderful!! Anybody out there that can shine a light on this?
Edit: Discovered a workaround.
Change port for consumer site to http://frontendflex.test:8080/doda
NameVirtualHost *:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "C:/xampp/htdocs/frontendflex/public"
ServerName frontendflex.test
</VirtualHost>
Changed to this in apache vhosts file
This works but i would like to know why other way does not work.
Hope this helps someone somewhere someday :)
I am trying to make an SEO friendly link for a downloads page
using codeigniter hosted on Azure Websites, now this is working:
www.example.com/downloads/viewfile/34
now when i generated this link :
www.example.com/downloads/viewfile/my-nice-file-name-34
the Url rewrite works great locally on a WAMP server, but when deployed to the remote (Azure Webites IIS ?) it gives the error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I believe that the cause is: dash symbols are not allowed on IIS but is there a way arround ?
After all, i found out that its not the dash symbols that are causing the problem, but the words in the url itself
like yesterday i had www.example.com/downloads/viewfile/example-file-34
to some reason, having your domain-name in the url segments makes that error apear, so i simply replaced "mydomain" into nothing before generating the Url segment
$fileName = str_replace('mydomain','',$fileName);
return url_title($fileName.$fileId);
Now the same link above is www.example.com/downloads/viewfile/file-34 and its working fine.
i also noticed that same behavior is experienced when using some words like : ajax, json.
I hope this would be helful to somone.
In your routes.php file
Find
$route['translate_uri_dashes'] = FALSE;
Replace with
$route['translate_uri_dashes'] = TRUE;
You may need to look also into
URI Routing Codeigniter 3
http://www.codeigniter.com/user_guide/general/routing.html
Codeigniter 2 URI Routing
http://www.codeigniter.com/userguide2/general/routing.html
I am extremely new to using phonegap,codeigniter and jQuery Mobile (My first project) and have currently created an app with jQuery Mobile on the Client side and on the Server side I used the Codeigniter framework to create a RESTful API. Now when I am developing locally the app with in the browser (not yet using phonegap) communicates just fine with the API and no problems occur.
I placed the Codeigniter API on a server yesterday and I am now encountering 2 problems:
The App which was built using jQuery Mobile keeps getting the
following error:
Origin localhost is not allowed by Access-Control-Allow-Origin.
Now I have done some reading up and most people say to use jsonp instead of json and also to use the following on the Server Side:
$CI->output->set_header("Access-Control-Allow-Origin: *");
$CI->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
$CI->output->set_status_header(200);
$CI->output->set_content_type('application/json');
Now my problem is I'm not entirely sure which one is used to fix the problem, weather it is both that need to be implemented etc. If they need to be fixed, how is it done? Is there a place that is well documented that can teach me how to deal with this problem, preferably I would like some where to read up on so I can learn?
The second problem is when I place the jQuery Mobile app into
phonegap and build it for Android. The app fails to get the
data from the server. Now is the reason for this because of the cross
domain error above or is this problem different? I also did some
reading up in this section as well and to my Android config.xml I
added the following code:
But I'm I still can't pull anything from the server. Like I said I'm a bit of a newbie but would really appreciate some help in this matter. Also I am aware that I haven't posted code but based on the comments I'll post which ever code the community needs to help solve this problem, just simply specify which code. Thank you for the help in advance!
About the Access-Control-Allow-Origin problem, I faced the same error and solved by placing this line <?php header('Access-Control-Allow-Origin: *'); ?> in the index.php which is in the root of the project.
This question hasn't been answered 100% but for now thanks to the help of #Niloy Saha, to fix the Access-Control-Allow-Origin error with with the Codeigniter RESTful frame work simply go to your controller in the Controller folder and right at the top paste;
header('Access-Control-Allow-Origin: *');
This then should allow you to communicate from the browser to the server and be able to get a response. After a good for hours of trying I managed to fix my problem. With in the Android project in the res/xml folder there is a file called config.xml. In that file be sure to have the following code:
<access origin="http://10.0.2.2*" subdomains="true"/>
and also make sure you have the following:
<uses-permission android:name="android.permission.INTERNET" />
in your AndroidManifest.xml. For me that seemed to get everything to work
I did similar thing as yours, Zend FW with API on server and jQuery Mobile App.
I've used JSONP, didn't use any Access-Control-Allow-Origin headers.
I have a method in my controller:
function returnData($data) {
header('Content-type: text/javascript');
echo $_GET['callback']. '('. json_encode($data). ')';
die();
}
At the end of API call i use it to return data.
Getting data in jQuery:
$.ajax({
dataType: "jsonp",
url: url,
data: {someparam: 'value'},
success: function(data) { /* ur data is here */ }
});
Does anyone know of a URL to get your Skype status using JSONP?
I've only found an XML status URL so far (http://mystatus.skype.com/username.xml).
(I'm trying to query Skype using AJAX. Yes, I could use a server-side proxy script to beat the cross-domain limits, but a direct call would be awesome.)
Simon.
Well apparently you can get a text-only version of the status by changing the extension to .txt:
http://mystatus.skype.com/username.txt
It will return "Online" or "Offline". About the Cross-domain AJAX, you can only do it via server and direct call is definitely not allowed.
You might change the headline to 'JSONP' instead of JSON. That's what you want.
JSONP hijacks cross domain fetches like this to work, without server proxies, by carrying the data in fetches. It's like the most hackish useful technology I come to mind, right now. :)
I nagged Skype about this - the easiest way out would be for their servers to have an official, documented JSONP interface. I hope they'll do that.
In the mean time, this is how I got the problem solved:
Placed this PHP script on my server, alongside the usual HTML: http://benalman.com/projects/php-simple-proxy/
Edited the configuration of it like so:
$enable_native = true;
$valid_url_regex = '/^http:\/\/mystatus\.skype\.com\/myuserid.*/';
This allows it to fetch (via curl running on the server) the mystatus.skype.com/myuserid.num (or .txt) information.
Fetching from JS with URL:
ba-simple-proxy.php?url=http%3A%2F%2Fmystatus.skype.com%2Fmyuserid.num&mode=native&full_status=1
That's it. Pheeew... :)
Also you can retrieve it using PHP
function getSkypeStatus($username) {
$data = file_get_contents('http://mystatus.skype.com/' . urlencode($username) . '.xml');
return strpos($data, '<presence xml:lang="en">Offline</presence>') ? 'Offline' : 'Online';
}
OR
function getSkypeStatus($username) {
$data = file_get_contents('http://mystatus.skype.com/' . urlencode($username) . '.xml');
preg_match('#<presence xml:lang="en">(.*?)</presence>#i', $data, $match);
return isset($match[1]) ? $match[1] : 'Error retrieving status';
}
Cheers!
Thanks to Bradgrafelman from - http://www.phpbuilder.com/board/showthread.php?t=10361050