Retrieving events from mailgun account - php

I'm trying to keep track of all events happening on my Mailgun account. As per the documentation, something like this would work
$mailgun->events()->get('example.com');
My code is as below
$mg = Mailgun::create('API KEY');
$queryString = array(
'begin' => 'Tue, 1 October 2019 09:00:00 -0000',
'ascending' => 'yes',
'limit' => 25,
'pretty' => 'yes',
'subject' => 'pulse'
);
# Make the call to the client.
$result = $mg->events()->get('example.com', $queryString);
The result is a string, Mailgun Magnificent API.
I have also tried $result = $mg->events()->get('example.com'); with similar results
I expceted a detailed JSON Object displaying my events or probably an unauthorized error message. Is there something I could be missing?

Related

omise PHP get all charges

Omise PHP get all charges
ref : https://www.omise.co/charges-api
$charges = OmiseCharge::retrieve();
this code gives me 20 records which is okay.
$response = OmiseCharge::retrieve('',OMISE_PUBLIC_KEY,OMISE_SECRET_KEY);
this also gives me first 20 records.
but my requirement is fetch all charges with date params.
$param = array(
'from' => '2014-10-20 00:00:00',
'to' => '2014-09-25 00:00:00'
);
$response = OmiseCharge::retrieve($param);
this gives an error.
Fatal error: Uncaught exception 'OmiseNotFoundException' with message 'charge Array was not found'
what i am doing wrong.
currently Omise-PHP library doesn't support for passing array at the first parameter.
(As your solution) you have to pass it as string (including other filters, such as 'limit', 'offset').
$param = array(
'limit' => 40,
'offset' => 40,
'from' => '2011-10-20 00:00:00',
'to' => '2016-09-25 00:00:00'
);
$charges = OmiseCharge::retrieve('?'.http_build_query($param));
I don't know this library but after quick search some tips:
First of all (if you not already done this) read this doc about pagination.
I found that date has different format: iso8601 what means for ex 2014-10-20T00:00:00Z.
limit to 20 records you can change to 100, try to use pagination
BTW. Interesting API.
$param = array(
'from' => '2011-10-20 00:00:00',
'to' => '2016-09-25 00:00:00'
);
$response = OmiseCharge::retrieve('?'.http_build_query($param));
worked for me.

Can we use post method for getting data?

I've many parameters(filters) for getting data from API so i've used POST method for sending parameters(filters) to API . Its working fine but I want to know its ok to use POST function for getting list from API ?
Reason for using POST instead GET :
If I've used GET function it will create problem for array data and also We need to pass some string data that may contain some special characters so in GET method need lot off manual error handling.
Our application under development phase so when new parameter need to add every time we need to change the URL on all our applications where we use this API.
$filter = (object) array(
'page_name' => '',
'page_category' => 0,
'page_gender' => 'N',
'page_country' => 0,
'page_company' => 0,
'page_language' => 0,
'page_order' => 'ASC',
'page_order_field' => 'dlang_firstname',
'page_currency' => 47,
'page_currency_unit' => 1,
'page_currency_iso' => 'GBP',
'page_current' => $page,
'page_size' => env('PAGE_SIZE', 10),
);
Above data I've passing to API.Is there any other way to send data ?

Google Analytics SEO - PHP API

I have a PHP file which give's me google analytics data, such as pageviews, Top Pages, or Organic Data simple stuff.
Now I neet to get Stuff from the SEO Part.
For example: TOP 50 Search Keywords (with Impression and Clicks)
I can't find any help in the API how to get these values.
this is a example of my api call:
$params = array(
'dimensions' => array('date', 'pagePath', 'pageTitle'),
'metrics' => array('sessions', 'pageviews'),
'sort' => '-ga:sessions',
'filters' => null,
'startdate' => $startdate,
'enddate' => $enddate,
'startindex' => null,
'limit' => 25,
'mapping' => array('pagepath' => 'pagepath', 'pagetitle' => 'pagetitle', 'sessions' => 'visits', 'pageviews' => 'pageviews'),
);
$results = $this->service->data_ga->get($this->profile, $params['startdate'], $params['enddate'], $metrics, $optParams);
The search engine optimization data shown in Google Analytics actually comes from Google Search Console (Webmaster Tools) and is available from the Google Search Console API.
https://developers.google.com/webmaster-tools/?hl=en
You would need to update the Dimensions and Metrics of your query. The traffic dimensions and metrics should be of help.
Below is a simplified query which gets the number of impressions and clicks for various sources and keyword combinations:
$optParams = array(
'dimensions' => 'ga:source,ga:keyword',
'sort' => '-ga:impressions,ga:source',
'filters' => 'ga:medium==organic',
'max-results' => '25');
$metrics = 'ga:impressions,ga:adClicks';
$results = $this->service->data_ga->get(
'ga:XXXX',
'today',
'7daysAgo',
$metrics,
$optParams);
Your code must have some mapping that it does from the values in $param field to the actual dimensions and metric names. I would also encourage you to play around with the query explorer to get a field of what queries are possible.

Podio api task due_date format

I'm trying to get the Podio API (php-library) to return all tasks that have a due date withing a certain range. PodioTask::get_all() works fine, it returns all tasks (limited to 100). Of course that is not very useful so I add attributes as documented:
$tasks = PodioTask::get_all(array(
'org' => [my_organization_id],
'completed' => 'false',
'limit' => 100
)
);
Up until here behavior is still as expected. As soon as I attempt to add the due_date-attribute I get an error message saying Uncaught PodioBadRequestError: "The values are not in the right format" Request URL: http://api.podio.com/task/?org=[my_organization_id]&completed=false&due_date=&limit=100
I try to do it like this, which works fine for the filters on Podio items:
$tasks = PodioTask::get_all(array(
'org' => [my_organization_id],
'completed' => 'false',
'due_date' => array(
'from' => '2d',
'to' => '90d'
),
'limit' => 100
)
);
I tried replacing the from and to dates with absolute ones in the YYYY-MM-DD format (as a string, but also tried a DateTime-object), but I get the same error. I tried removing the array and just setting a single date (as a string and a DateTime object) and none of it works. I keep getting the message that the values are not in the right format. The documentation tells me the due_date-parameter is "The from and to date the task should be due between. For valid options see date filtering under the filter area." If I go there I end up with the documentation for filtering items and I am doing the exact same thing here as for items, which I can filter by date. (https://developers.podio.com/doc/tasks/get-tasks-77949)
It appears like the php-library expects a string, but the API needs the 'from' and 'to' properties.
Anyone got any ideas?
Try this
$attributes = array(
'org' => [my_organization_id],
'completed' => 'false',
'limit' => 100,
'due_date'=> $fromDate.'-'.$toDate
);
$tasks = PodioTask::get_all($attributes);
where $fromDate and $toDate are DateTime Objects.

Fetch emails from Gmail via OAuth2

I'm trying to fetch emails from gmail using PHP and CodeIgniter, and an OAuth2 library. I have already got OAuth2 set up to get the users access token, etc. I can get the users info by doing
public function get_user_info(OAuth2_Token_Access $token)
{
$url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&'.http_build_query(array(
'access_token' => $token->access_token,
));
$user = json_decode(file_get_contents($url), true);
return array(
'uid' => $user['id'],
'nickname' => url_title($user['name'], '_', true),
'name' => $user['name'],
'first_name' => $user['given_name'],
'last_name' => $user['family_name'],
'email' => $user['email'],
'location' => null,
'image' => (isset($user['picture'])) ? $user['picture'] : null,
'description' => null,
'urls' => array(),
);
}
What I want to do now is fetch some emails. I've googled for some code on how to get emails but the only thing I can see is https://mail.google.com/mail/feed/atom/. I found this on the Google OAuth2 Playground but I can't figure out how to use it apart from navigating to it directly.
Can anyone give me some suggestions? Ideally I want to fetch emails that are not just new (this seems to be what the link above does).
Using a REST-based interface you can currently only get the unread messages feed. If you want to access all emails of a user, you have to use IMAP. Google developed a method to do IMAP/SMTP authentication using OAuth2 that you can use.

Categories