(403) User does not have any Google Analytics account - google-analytics-api

i have issue with google api service account i have done successfull authentication and got the access token. when i try to run the query it shows error
Warning: You need to set Client ID, Email address and the location of
the Key from the Google API console:
http://developers.google.com/consoleThere wan a general error : Error
calling GE T
(403)
User does not have any Google Analytics account.
i have multiple websites and multiple accounts in it. the google account is an admin account please check the code below.
$key_file_location = 'key path';
$client = new Google_Client();
$client->setApplicationName("name");
$client->setClientId($client_id);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/analytics.readonly'),
$key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$client->setAccessType('offline_access');
$client->getAccessToken();
$service = new Google_Service_Analytics($client);
$analytics_id = 'ga:xxxxxx';
$lastWeek = date('Y-m-d', strtotime('-1 week'));
$today = date('Y-m-d');
try {
$results = $service->data_ga->get($analytics_id, $lastWeek, $today,'ga:visits');
echo '<b>Number of visits this week:</b> ';
echo $results['totalsForAllResults']['ga:visits'];
} catch(Exception $e) {
echo 'There was an error : - ' . $e->getMessage();
}

Related

sendgrid getting error : The from address does not match a verified Sender Identity

when i try to send email with From Name : xxx#gmail.com it is not working, i am getting this error : The from address does not match a verified Sender Identity , can anyone please help me how to verify gmail domain ? so i can send email from gmail also, here is my code for it
$email = new \SendGrid\Mail\Mail();
$email->setFrom("xxxx#gmail.com", "test");
$email->setSubject("Sending with Twilio SendGrid is Fun");
$email->addTo("xxxx#gmail.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$apiKey = 'xxxxxxx';
$sendgrid = new \SendGrid($apiKey);
try {
$response = $sendgrid->send($email);
echo '<pre>';
print_r($response);
exit;
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}

Access private facebook group's posts using Graph API ( v 7.0 )

I am trying to get private groups posts by using graph api v7.0 by unfortunately i did not get posts returned an error Graph returned an error: (#803) Cannot query users by their username (SAAME)
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/SAAME/feed',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
//$graphNode = $response->getGraphNode();
$data = (array) $response;
var_dump ($data);
https://developers.facebook.com/docs/graph-api/reference/v7.0/group/feed
Check out the requirements, especially the bold ones:
Your app must be approved for the Groups API feature.
The app must be installed on the Group. (can only be done as group admin)
A User access token. (i assume any user token of a group member is ok)

REST API post request authenticate with API Key

I'm building out a RESTful API. I'm using API keys for my GET requests (base64 encoded over https to be secure) however I'm confused how to "authenticate" with POST requests.
I've read about basic authentication but that uses a username and password.
Is it good practice/correct to authenticate a POST request with an API key also? Is that something you would include as part of the headers?
How do I process the authentication on the server side (endpoint)?
Here's an example of the endpoint that I have for logging in (POST request):
if ($_POST) {
$email = $_POST['email'];
$email = stripslashes($email);
$email = strip_tags($email);
$password = $_POST['password'];
$password = stripslashes($password);
$password = strip_tags($password);
// Regular Login
$user = system::shared()->customers->login(
$email,
$password,
$error
);
if ($user) {
$output = json_encode($user);
} else {
$output = "Incorrect email/password. Please try again.";
}
echo $output;
} else {
http_response_code(405);
}
How would I use the code above to "authenticate" an API key. Is that just a POST field?
Thank you for your assistance

Can't get instagram newly added business account through API

I am facing issue for Instagram business accounts retrieving from API.
Client is already authorized my app and after some time they converted there Instagram personal account to business account.
When i try to fetch newly added Instagram business account they are not showing in API response.
Every time i have to remove app from account and re-authorized. I re-authenticated app still not get newly added business account.
Guys any solution for this ??
Here is a screenshot for more info http://nimb.ws/zfwl7e
function fb_reauthenticate_relink()
{
$helper = $this->fb->getRedirectLoginHelper();
$permissions = ['email', 'public_profile', 'manage_pages', 'read_insights', 'publish_pages', 'instagram_basic', 'instagram_manage_comments', 'instagram_manage_insights'];
$loginUrl = $helper->getReAuthenticationUrl('facebook_reauthenticate_callback', $permissions);
redirect($loginUrl);
}
function facebook_reauthenticate_callback()
{
$helper = $this->fb->getRedirectLoginHelper();
try
{
$accessToken = $helper->getAccessToken();
} catch (Facebook\Exceptions\FacebookResponseException $e)
{
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e)
{
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$raw_accessToken = (string) $accessToken;
$oAuth2Client = $this->fb->getOAuth2Client();
$longLivedAccessToken = (string) $oAuth2Client->getLongLivedAccessToken($raw_accessToken);
$url = "https://graph.facebook.com/v3.1/me/accounts?fields=instagram_business_account,connected_instagram_account,global_brand_page_name,access_token&access_token=" . $longLivedAccessToken;
$request_response = $this->curl_request($url);
// In $request_response didn't get newly added business profile
}

Zend Calendar Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 401

I want inteface this script with google calendar using Zend Framework.
This code works locally but doesn't works on altervista.
The error is
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with
message 'Expected response code 200, got 401
<?php
require_once "Zend/Loader.php";
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
$user = "xxx#gmail.com";
$pass = "xxxxx";
$title= "Evento ";
$content="evento presso nome associaizone";
$where="luogo";
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cl');
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
$service = new Zend_Gdata_Calendar($client);
//
// Create a new entry using the calendar service's magic factory method
$event= $service->newEventEntry();
// Populate the event with the desired information
// Note that each attribute is crated as an instance of a matching class
$event->title = $service->newTitle($title);
$event->content= $service->newContent($content);
$event->where = array($service->newWhere($where));
// Set the date using RFC 3339 format.
$startDate = "2014-03-18";
$startTime = "14:00";
$endDate = "2014-03-19";
$endTime = "16:00";
$tzOffset = "-08";
$when = $service->newWhen();
$when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
$when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
$event->when = array($when);
// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$newEvent = $service->insertEvent($event);
?>
Zend_Gdata and ZendGData are out of maintenance.
Instead the recomendation is migrate to the official Google SDK https://code.google.com/p/google-api-php-client/