I have any adress recorded in my databse corresponding to the customers.
The trouble I met is concerning the including of a googlemap.
I have the following code that convert an adress to the polares.
function getCoordonnees($adresse) {
$url = "http://maps.google.com/maps/geo?q=" . urlencode($adresse) .
"&output=csv";
$csv = file($url);
$donnees = preg_split("#,#", $csv[0]);
return $donnees[2] . "," . $donnees[3];
}
The following code returns to me somethinbg like that
48.9381235,2.1329083
When I use the google map I have a picture like that :
Which comes from this url (generated by my function
http://maps.google.com/staticmap?center=48.9381235,2.1329083&zoom=15&size=300x300&maptype=mobile&markers=48.9381235,2.1329083,red&key=***********************KEY*GOOGLEMAP************&sensor=false
When I try to display that picture in my website, An error appears,
<img src="http://maps.google.com/staticmap?center=<?php echo $polar; ?>&zoom=15&size=300x300&maptype=mobile&markers=<?php echo $polar; ?>,red&key=***********************KEY*GOOGLEMAP************&sensor=false" style="border:double 2px" />
Where $polar is the polares.
Including this code in my website returns to me the following mistake :
Failed to load resource: the server responded with a status of 403 (Forbidden)
I have no idea from where comes this error. Actualy I do not think it comes from google map because on stackoverflow, the picture is displayed.
So I would ask if anybody know where can comes this mistake ? Is is from the server configuration or something else ? I've been looking for that since many times without answer.
Anykind of help will be much appreciated.
I was having the same issue and I decided to turn on Google Maps API v2
I already had Google Maps API v3 on but before messing with to many settings I turned them both on.
Now it works
Related
I'm using this library: https://github.com/googleapis/google-api-php-client
I created a simple PHP script that fetches some information from Google Search Console / Webmaster Tools about the performance of a domain I own.
It is not intented to autentify on behalf of a user who visits the page and own their own website. It's intended to show information about MY website and it identifies via a fixed service account. More detail below.
Here's the PHP code:
<!DOCTYPE html>
<html>
<head>
<title>Google Webmaster Tools test</title>
</head>
<body>
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
require_once ('./path/to/the/autoload.php');
echo "Instantiating client<br>";
$client = new Google_Client();
$credentials = file_get_contents ('./test_search_console_credentials.json', true) ;
echo "Configuring client<br>";
$client->setAuthConfig(json_decode($credentials,true));
$client->setScopes(['https://www.googleapis.com/auth/webmasters.readonly']);
$client->setAccessType('offline');
echo "Instantiating Webmasters service <br>";
$service = new Google_Service_Webmasters($client);
$query = new \Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$date_now = date('Y-m-d');
$date_past = date('Y-m-d', time()-3600*24*30);
$query->setStartDate($date_past);
$query->setEndDate($date_now);
$query->setDimensions(['page','query']);
$query->setSearchType('web');
$pfilter=new \Google_Service_Webmasters_ApiDimensionFilter();
$pfilter->setDimension('page');
$pfilter->setOperator('equals');
$pfilter->setExpression('https://example.com/');
$fgroup= new Google_Service_Webmasters_ApiDimensionFilterGroup();
$fgroup->setFilters([$pfilter]);
$query->setDimensionFilterGroups([$fgroup]);
try {
$u = $service->searchanalytics->query('https://example.com', $query);
echo '<table border=1>';
echo '<tr>
<th>#</th><th>Clicks</th><th>CTR</th><th>Imp</th><th>Page</th><th>KEYword</th><th>Avg. pos</th>';
for ($i = 0; $i < count($u->rows); $i++) {
echo "<tr><td>$i</td>";
echo "<td>{$u->rows[$i]->clicks}</td>";
echo "<td>{$u->rows[$i]->ctr}</td>";
echo "<td>{$u->rows[$i]->impressions}</td>";
echo "<td>{$u->rows[$i]->keys[0]}</td>";
echo "<td>{$u->rows[$i]->keys[1]}</td>";
echo "<td>{$u->rows[$i]->position}</td>";
echo "</tr>";
}
echo '</table>';
} catch(\Exception $e ) {
echo $e->getMessage();
}
?>
</body>
</html>
So I did the following:
In Google Cloud Console I created a project and I enabled the Google Search Console API and also the Legacy one just in case:
I created a Service Account for the project:
For the Service Account, I created a key:
That generated a JSON file which is the one I load from the PHP code above.
In Google Search Console I have a domain property
whose ownership I verified via DNS. As you can see, I can see the data in the web interface.
I granted access to the abovementioned Service Account's email address with FULL access
Yet, when I try the script above, I get the error:
{ "error": { "code": 403, "message": "User does not have sufficient permission for site 'https://********.com'. See also: https://support.google.com/webmasters/answer/2451999.", "errors": [ { "message": "User does not have sufficient permission for site 'https://*******.com'. See also: https://support.google.com/webmasters/answer/2451999.", "domain": "global", "reason": "forbidden" } ] } }
Obviously the linked Help Center page doesn't help.
I have done the exact same thing with half a dozen other websites, all with the exact same procedure, with the same project, Service Account and credentials, and it works with most of them.
The only difference I can see between the properties with which it works and those with which it doesn't, is that the ones that work are properties that have existed for years, way before I even created the Google Cloud Platform project; and they were not "domain" properties, but url-prefix-based ones, that is, properties that either start with https:// or plain http://, either with or without the www., and they only work with the proper protocol and the right www prefix or lack thereof. And in those, you verify the ownership by uploading a file with a given path and name that Google gives you. However, I have tried to create a property like that for the newer domain that I'm trying to get to work, and that doesn't work either.
It's almost as if Google's api refused to work with properties created after a certain date.
NOTE: don't tell me I need Owner permissions instead of Full. I have already tried that (which you can only do through an older interface difficult as hell to find) and it makes no difference whatsoever. The older websites work both with Full and Owner permissions; the newer one doesn't work with either.
I found the answer here:
Webmasters API User does not have sufficient permission for site
(MartijnvdB's answer in case the deep link to the specific answer breaks).
I needed to change this:
$u = $service->searchanalytics->query('https://example.com', $query);
to this:
$u = $service->searchanalytics->query('sc-domain:example.com', $query);
There are two types of Google Search Console properties: domain-type and prefix-type. For domain-type properties you need to pass the name of the property as https://www.example.com (with http or https, with or without the www matching the exact prefix of the property). For domain-based properties you need to pass it as sc-domain:example.com.
I had tried with just example.com without any kind of prefix, but that didn't work. I don't know why the API can't just accept that and prepend sc-domain: when needed.
The PHP library has no documentation whatsoever, and the documentation of the API itself is unbelievably poor too, as is usual for Google APIs.
Once you already know the answer, you can find it documented here:
https://developers.google.com/webmaster-tools/search-console-api-original/v3/searchanalytics/query
siteUrl string The URL of the property as defined in Search Console. Examples: http://www.example.com/ (for a URL-prefix property) or sc-domain:example.com (for a Domain property)
Note that it says "as defined in Search Console". When browsing the Search Console as a user, you never see the name of the property as sc-domain:... anywhere.
Hi guys I've made a website on steam with steam node bot but sometimes after login into steam I have this appear above over my website.
My developer told me is steam api issue. Is it true?
https://gyazo.com/3b72a35341e28761eaee2c8bcbfee7b0
Using a similar site, is.steam.rip you can make an api call to the website and allow users to view your website depending on the status of steam.
First open the api which is saved as a json string. Decode it and access the SteamCommunity part of SteamStatus
$steam = file_get_contents('http://is.steam.rip/api/v1/?request=SteamStatus') or die("Is.Steam.RIP is currently offline");
$json_a = json_decode($steam);
$steamOnline= $json_a->{'result'}->{'SteamStatus'}->{'services'}->{'SteamCommunity'};
If you put this in a separate file say checkSteam.php and include it in your main page you can do
include 'checkSteam.php';
and using an if statment:
if($steamOnline !== "offline") {
// Show the users your website
}
else {
// deny access since steam is down
}
I don't know all of the status's this api offers but it often shows as 'delayed' hence I only use the !== "offline"
You can find more api's on their main site here
https://steamstat.us
Try accessing that link in browser (one from file_get_contents) and if it throws 503 then it is Steam Issue
google login
I am working on php . I have made app on Google . If u can see my link , I am using state parameter , in which state=reg . In my callback page , I am trying to get this value ie $_get['state'] but its not showing me anything . Am i doing the right way ?
I've never seen a Client ID that begins "**", but in your link I see client_id=%2a%2a43760%2a%2a%2a%2a%2a-cp7 which really looks wonky. Are you sure that’s right?
We are attempting to use the Google Place Photo Requests
(https://developers.google.com/places/documentation/photos#place_photo_requests)
API to fetch photos, but are constantly getting the quota exceeded image.
We have signed up for a paid account, as well as set up a brand new account, and continue to get this error.
To reproduce we:
1) First ran the Place Details request from the server (/maps/api/place/details/json) via PHP.
2) Then from this result set we fetched the (['result']['photos'][0]['photo_reference']) photoreference.
3) With the photoreference, key, sensor and maxwidth variables we called /maps/api/place/photo (via PHP).
We can not seem to get this to work. Has anybody else successfully used this or has any advice?
Sounds like you are either sending us a lot of requests, or you aren't adding your key to the photo fetch. Have you had any successful requests? If not, I'd suspect your keys are missing and/or incorrect.
Try this code.. It works for me
<h3>Images From Google </h3>
<?php
$company_name = 'walmart';
$data_ref = file_get_contents("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=Latitude ,Longitude&radius=100&name=".$company_name."&types=store&sensor=false&key=MYKEY");
$data_ref_de = json_decode($data_ref);
if($data_ref_de->status=='OK')
{
foreach($data_ref_de->results as $result)
{
if(isset($result->photos) && count($result->photos))
{
foreach($result->photos as $photos)
{?>
//Display Image
<img src="https://maps.googleapis.com/maps/api/place/photo?maxwidth=600&photoreference=<?php echo $photos->photo_reference; ?>&sensor=true&key=MYKEY" />
<?php
}
}
}
}
And also be sure that you have enabled the Places API Service
I'm looking for a good, simple PHP function to get my latest Facebook status updates. Anyone know of one?
Thanks!
EDIT: I've added a half-solution below.
Or if anyone knows a good way to read in the RSS feed and spit out the recent status update?
A quick check on PEAR found Services_Facebook
This is an incomplete answer, but this is what I've gotten so far:
First: add the developer application on FB. Then create a new application. Call it whatever you want.
Second: Download the PHP client. Dump it somewhere on your webhost, i.e. /facebook/
Third: Copy the following beginner code to get yourself started into a php file:
<?php
require_once('facebook/php/facebook.php');
$facebook = new Facebook("YOUR_API_KEY","YOUR_SECRET_KEY");
$result = $facebook->api_client->fql_query("SELECT status FROM user WHERE uid = YOURIDNUMBER");
// OR --- they both get the same data
$result = $facebook->api_client->users_getInfo(YOURIDNUMBER,'status');
print_r($result);
echo "<pre>Debug:" . print_r($facebook,true) . "</pre>"; // debug info
?>
Other info:
You must be logged in and have the
application added. OR you give the
application offline_access
permissions and have the
aapplication added.
You can add offline_access by typing
in the following url:
http://www.facebook.com/authorize.php?api_key=YOUR_API_KEY&v=1.0&ext_perm=offline_access
more info on permissions found here: http://wiki.developers.facebook.com/index.php/Extended_permissions
I'm at a stopping point: anything my
program calls the fql query or
users_getInfo, my page stops
executing the php? I'm guessing
there are a limited amount of calls
for new applications? I've never
done any FB development so I'm
completely new to it. Maybe make
the call and save your recent status
(or most recent statuses) in your
own DB to prevent excessive calls to
the API?
I hope this helps someone get started!
EDIT: It seems that FB won't let you access someones status, even if the offline_access is on, unless you are that person or their friend (depending on their privacy settings).
I did however, finally manage to find the RSS feed in the new profile version: http://www.new.facebook.com/minifeed.php?filter=11
I have found a way to fetch your latest facebook status. This is how you do it:
1) Create a facebook app, and copy your application secret and application id.
2) Grant the app read_stream and offline_access to your profile. (http://developers.facebook.com/docs/authentication/permissions) To fetch your latest status the app needs an access_token. With offline_access granted the access_token should "never" expire. The easiest way to do this is to click the button generated by this code: (be sure to fill in 'your app id' and set cookie to true!)
<fb:login-button perms="read_stream,offline_access"></fb:login-button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});</script>
3) Now try to find out what access_token it is using. The access_token is saved in the fbs_appId cookie. Locate it using your browser or using $_COOKIE['fbs_appId']. Look for access_token=....
4) Now that you have a (hopefully) never expiring access_token you can use the following code:
$access_token='xxxxxxxxxxxxxxxxxxxx';
$appId='123456789132456789';
$appSecret='xxxxxxxxxxxxxxxxxxxx';
$profileId='123456789';
//http://github.com/facebook/php-sdk/blob/master/src/facebook.php
require 'facebook.php';
$facebook = new Facebook(array('appId' => $appId,'secret' => $appSecret));
$response = $facebook->api('/'.$profileId.'/feed?limit=1&access_token='.$access_token);
5) The message part should be located: $response['data'][0]['message']
I don't know HOW long the access token is valid. Facebook says:
Enables your application to perform authorized requests on behalf of the user at any time. By default, most access tokens expire after a short time period to ensure applications only make requests on behalf of the user when the are actively using the application. This permission makes the access token returned by our OAuth endpoint long-lived.
Here is a REALLY simple function if you just want to get the latest status. It doesn't depend on the Facebook SDK or anything. You just need CURL and JSON support.
Simple PHP function to get facebook status
I never seem to get along with PEAR, but if you have better luck than I, then the PEAR solution seems the best route long term.
Another idea is to explore the Facebook Developer API library and see if that might give you anything you are looking for.
Lastly, there used to be a way to get an RSS feed... but I can't seem to find any instructions that work anymore, but you might poke around Facebook help if that interests you. Mine ends up looking something like this:
http://www.new.facebook.com/feeds/status.php?id=[idnumber]&viewer=[viewer]&key=[key]&format=rss20
I got it working using Jens' post to retrieve a valid access_token. Then, I extracted the status messages and the time of posting from the xml file using the following code (you can change $limit to display more or less status messages, or use a form to change it).
Be sure to put in your Facebook ID and the access token you got from the app you created (see Jens' post). You can check the output of this script here.
Have fun!
<?php
if(isset($_POST['limit'])) {
$limit = $_POST['limit'];
}
else {
$limit = 3; // number of status messages to display
}
$f = fopen ("https://api.facebook.com/method/status.get?uid=YOUR_FACEBOOK_ID&limit=".$limit."&access_token=YOUR_ACCESS_TOKEN", "r");
while ($line= htmlentities(fgets($f))) {
if ($line===FALSE) print ("FALSE\n");
else
{
$content = $content." ".$line;
}
}
fclose ($f);
$message = explode("<message>", $content); // search for the <message> tag
$message_cnt = count($message);
$msg_index = 0;
$time = explode("<time>", $content); // search for the <time> tag
for($i=1; $i<$message_cnt; $i++)
{
$tmp = explode("</message>", $message[$i]);
$msg[$msg_index] = $tmp[0]; // status message
$tmp2 = explode("</time>", $time[$i]);
$t[$msg_index++] = $tmp2[0]; // time of posting
}
for($i=0; $i<$msg_index; $i++)
{
echo("<span class=\"status\">".preg_replace('!\015\012|\015|\012!','<br>',$msg[$i])."</span><br>\n
<span class=\"date\">on ".date("d.m.Y", $t[$i])." at ".date("H:i",$t[$i])."</span><br><br>\n");
}
?>
I have tried loads of tutorials over the last few days and none of them have worked. I think it may be due to facebook changing their api requirements. This is the only one I found that works at the moment:
http://www.deanblog.co.uk/article/13/adding-a-facebook-status-feed-to-your-website-with-php
Just use PHPforFB framework (www.phpforfb.com/en/) for the fastest way.
The code looks like this:
require_once('phpforfb_framework.php');
$structInit = array('app_id' => APP_ID,'app_name' => APP_NAME,'sec_key' => APP_SECKEY);
$FacebookAPP = new PHPforFB($structInit);
if($FacebookAPP->lastErrorCode>0){
//Creation failed => Display error message and exit
echo "PHPforFB Error: ".$FacebookAPP->lastErrorCode." -> ".$FacebookAPP->lastError;
}else{
//PHPforFB framework established
if($FacebookAPP->userLoggedIn === TRUE){
//If the user is logged in at Facebook:
//Here you can determine if the user has at least once before
//granted basic permissions to your application.
if($FacebookAPP->userAuthenticated === FALSE){
//The user has not yet granted permissions
//**your code here**
}else{
//The user has already granted permissions, therefore his Facebook ID
//is known to us. It is always available in $FacebookAPP->userID:
$userID = $FacebookAPP->userID;
//**your code here**
}
}
}
Since I couldn't use the API route, I went with the RSS found at: http://www.new.facebook.com/minifeed.php?filter=11
And used the following PHP function, called StatusPress, with some of my own modifications, to parse the RSS feed for my Facebook status. Works great!
<?php
// see http://github.com/facebook/php-sdk/blob/master/facebook.php
require './facebook.php';
// Create our Application instance.
// see http://www.youtube.com/watch?v=jYqx-RtmkeU for how to get these numbers
$facebook = new Facebook(array('appId' => 'XXX','secret' => 'XXX'));
// This call will always work since we are fetching public data.
// this could be /username or /username/friends etc...
// see developer api for FQL for examples
$status = $facebook->api('/haanmc/feed?limit=1');
?>
<p><?php print $status['data'][0]['message']; ?></p>
<p>Likes: <?php print $status['data'][0]['likes']; ?> | Comments: <?php print count($status['data'][0]['comments']['data']); ?></p>
<textarea style="width: 95%; height: 600px;"><?php print_r($status); ?></textarea>