Google calendar push notifications do not notify on delete - php

I have registered push notifications. Updates and creations work just fine, but I am not able to receive deleted events.
I am setting the channel like this
public function setUpPushNotificationsChannel($lengthHours = 168){
$this->cancelPushNotificationsChannel();
$channel = new Google_Service_Calendar_Channel();
$channel->setId(create_guid());
$channel->setType('web_hook');
$channel->setAddress( $this->url);
$channel->setToken(Utils::encrypt($this->pushSecret);
$dateTime = new DateTime();
$dateTime->add(date_interval_create_from_date_string("$lengthHours hours"));
//timestamp is in milliseconds for google -.-
$channel->setExpiration($dateTime->getTimestamp() * 1000);
//this does not do anything
$optParams = array(
'singleEvents' => true,
'showDeleted' =>true,
);
$channel = $this->service->events->watch($this->getGoogleCalendarId(),$channel,$optParams);
$this->gcalendarSetting->gcalendar_push_channel_id_c = $channel->getId();
$this->gcalendarSetting->gcalendar_resource_id_c = $channel->getResourceId();
$this->gcalendarSetting->save();
}
I could not find anything in the google doc, maybe I am missing some parameter for deleted events?
Thanks

It turns out, that the problem is not in deleted events, but in everything. The notifications just quite often don't arrive and I just had bad luck while I was testing it. It seems that almost 50% of changes are not pushed, which is quite unsatisfying.

Related

How to toggle on Monetise with ads option on YouTube with API

I am building an application that uploads videos to YouTube using PHP Google Client library. I was able to upload videos but couldn't toggle on the Monetise checkbox. There is very little information on the web.
I found this link to be helpful. http://www.techtonet.com/youtube-upload-videos-with-partner-api-in-php/#ipt_kb_toc_51_6
But I couldn't managed to do this.
Please help with this.
// Create a claim resource. Identify the video being claimed, the asset
// that represents the claimed content, the type of content being claimed,
// and the policy that you want to apply to the claimed video.
$claim = new Google_Service_YouTubePartner_Claim();
$claim->setAssetId($assetId);
$claim->setVideoId($videoId);
$claim->setPolicy($policy);
$claim->setContentType("audiovisual");
// Insert the created claim.
$claimInsertResponse = $this->_youtubePartner->claims->insert($claim,
array('onBehalfOfContentOwner' => $contentOwnerId));
# Enable ads for the video. This example enables the TrueView ad format.
$option = new Google_Service_YouTubePartner_VideoAdvertisingOption();
//$option->setAdFormats(array("overlay", "trueview_instream", "standard_instream"));
$option->setAdFormats(array("trueview_instream", "standard_instream"));
$setAdvertisingResponse = $this->_youtubePartner->videoAdvertisingOptions->update(
$videoId, $option, array('onBehalfOfContentOwner' => $contentOwnerId));
For me is working with this code
$youtubePartner = new \Google_Service_YouTubePartner($this->client);
$asset = new \Google_Service_YouTubePartner_Asset();
$metadata = new \Google_Service_YouTubePartner_Metadata();
$youtubePartner = new \Google_Service_YouTubePartner($this->client);
$metadata->setTitle("Asset Title"));
$metadata->setDescription("AssetDescription");
$asset->setMetadata($metadata);
$asset->setType("web");
$assetInsertResponse = $youtubePartner->assets->insert($asset, [
'onBehalfOfContentOwner' => $this->contentOwnerId
]);
$assetId = $assetInsertResponse['id'];
$ratio = 100;
$type = "exclude";
$territories = [];
$owners = new \Google_Service_YouTubePartner_TerritoryOwners();
$owners->setOwner($this->contentOwnerId);
$owners->setRatio($ratio);
$owners->setType($type);
$owners->setTerritories($territories);
$ownership = new \Google_Service_YouTubePartner_RightsOwnership();
$ownership->setGeneral([$owners]);
$youtubePartner->ownership->update($assetId, $ownership, ['onBehalfOfContentOwner' => $contentOwnerId]);
$policy = new \Google_Service_YouTubePartner_Policy();
$policyRule = new \Google_Service_YouTubePartner_PolicyRule();
$policyRule->setAction("monetize");
$policy->setRules(array($policyRule));
$claim = new \Google_Service_YouTubePartner_Claim();
$claim->setAssetId($assetId);
$claim->setVideoId($videoId);
$claim->setPolicy($policy);
$claim->setContentType("audiovisual");
$claimInsertResponse = $youtubePartner->claims->insert($claim, [
'onBehalfOfContentOwner' => $contentOwnerId,
]);
If is not working for you put all code here, after uploading video, once you have videoId from Youtube.
You only need to change $videoId and $contentOwnerId
The code that shows you above is the part that corresponds only to the monetization. You need to have the video already uploaded to youtube. If you have the id of the video and contentOwnerId the code should work without changing anything else. Try only this part of the code and if it does not work for you, get me the answer of toutube to the following request
$claimInsertResponse = $youtubePartner->claims->insert($claim,
array('onBehalfOfContentOwner' => $contentOwnerId));
If successful, this method returns a claim resource in the response body. Otherwise it returns an error. If it returns an error, give me the error, so I can tell you what is happening.

Display Facebook ADs Statistics on webpage using Facebook Ads API in PHP

Does anyone know how to fetch all facebook ads statistics and display on webpage using Facebook Ads Api-PHP SDK. I am using this API and I am getting campaign details like name of campaign, id, status. but not able to get impressions,clicks, spent.
What I am doing let me share with you:
1) I am getting access token by authorizing user
2) After getting access token, I am using below code
$account = new AdAccount('act_XXXXXXXXXXXXXXX');
$account->read();
$fields = array(
AdCampaignFields::ID,
AdCampaignFields::NAME,
AdCampaignFields::OBJECTIVE,
);
$params = array(AdCampaignFields::STATUS => array(AdCampaign::STATUS_ACTIVE,AdCampaign::STATUS_PAUSED,),);
$campaigns = $account->getAdCampaigns($fields, $params);
/* Added By Jigar */
$campaign = new AdCampaign('XXXXXXXXXXXXXXXX');
$compainDetails = $campaign->read($fields);
3) then printing the array
echo "<pre>";
print_r($compainDetails);
exit;
If anyone know any suggestion in above code, please share. All code is in PHP. Dose anyone have any tutorial that fetch all above required data then share it
You could try to use the facebook insights api instead of $campaign->read. Here's an example:
https://developers.facebook.com/docs/marketing-api/insights/v2.5#create-async-jobs
What you have to do to get impressions, click and spent is to add these fields to the $fields param. In your case, the complete code should look like the following:
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Values\InsightsLevels;
use FacebookAds\Object\Values\InsightsFields;
$campaign = new Campaign();
$fields = array(
InsightsFields::IMPRESSIONS,
InsightsFields::UNIQUE_CLICKS,
InsightsFields::CALL_TO_ACTION_CLICKS,
InsightsFields::INLINE_LINK_CLICKS,
InsightsFields::SOCIAL_CLICKS,
InsightsFields::UNIQUE_SOCIAL_CLICKS,
InsightsFields::SPEND,
);
$params = array(
'level' => InsightsLevels::CAMPAIGN,
);
$async_job = $campaign->getInsightsAsync($fields, $params);
$async_job->read();
I don't know what exactly the "click" param means for you, but if you take a look at all these click params, I'm sure you'll find it or you'll know how to calculate it.
For a complete list of fields available on insights objects, have a look at: https://github.com/facebook/facebook-php-ads-sdk/blob/master/src/FacebookAds/Object/Fields/InsightsFields.php
Hope that helps.
Regards, Benjamin

API Google Calendar, Hangout is not created

We have a PHP application and when we create an event in Google Calendar using de API, this event is generated without Hangout Link, but if we create the event manually, the event is created with the Hangout Link. The option to create automatically hangouts when we create an event is checked.
The code is:
$event = new Google_Service_Calendar_Event();
$event->setSummary($summary);
$event->setLocation('hangout');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($startDate->format(\DateTime::ISO8601));
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($endDate->format(\DateTime::ISO8601));
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail($this->masterAccount);
$attendees= [];
$attendees[] = $attendee1;
foreach($company->getUsers()->toArray() as $user){
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail($user->getEmail());
$attendees[] = $attendee1;
}
$event->attendees = $attendees;
$createdEvent = $this->google_calendar_service->events->insert($company->getCalendar()->getCalendarId(), $event);
If we use the form https://developers.google.com/google-apps/calendar/v3/reference/events/insert#try-it to create de Event, the hangout link is created without problems.
Any solutions?
Thanks :)
I know this topic is a bit old, but there are many people still struggling with making Calendar API work. After countless forums visited, hours of reading documentation and hitting my head against the wall I finally figured out, the key element is to set requestId.
In the time i've implemented this, this parameter wasn't mandatory and i skipped it.
Thats being said, my request looks like this:
$event = new Google_Service_Calendar_Event(); //creating empty event
$event->setSummary("Staff meeting"); //title
$event->setLocation("Room 101"); //location
$event->setDescription("We will talk about salary raise!"); //description
$event->setColorId(9); //make it shine by setting color
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($startDate->format(DateTime::ISO8601));
$start->setTimeZone('Europe/Warsaw');
$event->setStart($start); //set start
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($endDate->format(DateTime::ISO8601));
$end->setTimeZone('Europe/Warsaw');
$event->setEnd($end); //set end
$event->setGuestsCanSeeOtherGuests(false); //I dont want others to see who's invited
$event->setGuestsCanModify(false); //I dont want others to modify event
$event->setGuestsCanInviteOthers(false); //I dont want others to invite
$event->setAnyoneCanAddSelf(false); //I allow only people invited by me, not some strangers walking by
//this part should be executed in loop, for every guest
$attendee = new Google_Service_Calendar_EventAttendee();
$attendee->setEmail("staffmeber1#mywebsite.com");
$attendee->setResponseStatus('accepted');
$attendees[] = $attendee;
//When the list is completed, set guests in event
$event->setAttendees($attendees);
//The most important part about creating hangout
$conferenceData = new Google_Service_Calendar_ConferenceData(); //defining we have conference
$req = new Google_Service_Calendar_CreateConferenceRequest(); //requesting google to create video meeting
$req->setRequestId("req_".time()); //some random string/number changed every call. according to docs subsequent calls with the same request id are ignored
$conferenceData->setCreateRequest($req); //set request for videoconference in conference data
$event->setConferenceData($conferenceData); //set conference data in out event
$creator = new Google_Service_Calendar_EventCreator();
$creator->setDisplayName("Big boss");
$creator->setEmail('boss#mywebsite.com');
$event->setCreator($creator);
$event->setStatus('confirmed'); //lets say everyone is attending :D
$result = $this->calendarClient->events->insert($this->calendarObject->getId(), $event, ['conferenceDataVersion' => 1, 'sendUpdates' => "none"]); //dont forget about conferenceDataVersion or every conference data will be ignored
Working with Python here also faced issue, of events not being created with Hangouts. It seems settings can not be changed from program, but as SGC pointed out, I just changed google calendar settings from UI to add hangouts on every event created.

How to change 'From' address and target calendar when creating events with Google API

I've managed to install the google API using composer and ZF2, and have successfully worked through the tribulation that is getting the P12 key, configuring the app, and configuring the Google_Client instance.
I've also managed to create events like so:
/** #var \Google_Service_Calendar $calendar */
$calendar = $this->getServiceLocator()->get('GoogleCalendar');
$event = new \Google_Service_Calendar_Event();
$event->setSummary( "This is a test" );
$dts = new \Google_Service_Calendar_EventDateTime();
$dts->setDateTime( date( "Y-m-d\\TH:i:s.000-04:00" ) );
$event->setStart( $dts );
$dte = new \Google_Service_Calendar_EventDateTime();
$dte->setDateTime( date( "Y-m-d\\TH:i:s.000-04:00", time() + 1800 ) );
$event->setEnd( $dte );
$att = array();
foreach( $emails as $e )
{
$attendee = new \Google_Service_Calendar_EventAttendee();
$attendee->setEmail( $e );
$att[] = $attendee;
}
$event->setAttendees( $att );
$x = $calendar->events->insert( "primary", $event, array( 'sendNotifications' => true ) );
return new JsonModel( array( 'success' => true ) );
The invitation comes from the application's client email, but I'd like to make it come from a particular email. How can I change the invitation?
Also, we subscribe to Google for Business ourselves; is it possible to create events within our business calendars rather than 'primary' on the app itself?
Thanks for your help!
Looking at the actually API documentation at Google, I'm not seeing a property to change who the calendar invite comes from. I'm not sure that would be a great thing to be able to do, you could then setup calendar events/invites from the CEO of a company about the company going out of business or some other crazy calendar invite without approval.
Your best bet would be to authorize the application for the account you want to use, then use the token from that account to insert calendar events.

Get users details in mixpanel api

I'm trying to get user details via Mixpanel analytics but I am having difficulties to properly grasp how i should do this… data has been set using
mixpanel.people.identify()
Events and Segmentation requests seem to be ok; but I can't figure out how to query a request on the Engage endpoint.
as it turns out—there might be other ways to find this out but this one works for me:
you need to get engagement data this way
$data = $mp->request(array('engage'));
foreach($data->results as $user) {
$email = $user->{'$properties'}->{'$email'};
$last_seen_date = $user->{'$properties'}->{'$last_seen'};
$distinct_id = $user->{'$distinct_id'};
}
the distinct_id can then be used within the foreach() loop above to get events registered with this user:
$endpoint = array('stream', 'query');
$parameters = array(
'distinct_ids' => json_encode(array($distinct_id)),
'from_date' => '2014-02-10',
'to_date' => '2014-02-25',
);

Categories