How to access any other's google calendar using google php api - calendar

I need access any other user's google calendar freebusy using google php api. Can any one help me step by step process to implement that. I have already checked the https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query#response but nothing fruitful I got.
My Approach
session_start();
require_once ('libraries/Google/autoload.php');
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("email");
$client->addScope("profile");
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->addScope(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAccessType('offline');
$service = new Google_Service_Oauth2($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
exit;
}
/************************************************
If we have an access token, we can make
requests, else we generate an authentication URL.
************************************************/
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}
$client->setApplicationName("My Calendar"); //DON'T THINK THIS MATTERS
$client->setDeveloperKey($api_key); //GET AT AT DEVELOPERS.GOOGLE.COM
$cal = new Google_Service_Calendar($client);
$calendarId = 'any_other_user_email#gmail.com';
$freebusy_req = new Google_Service_Calendar_FreeBusyRequest();
$freebusy_req->setTimeMin($minTime);
$freebusy_req->setTimeMax($maxTime);
$freebusy_req->setTimeZone($time_zone);
$freebusy_req->setCalendarExpansionMax(10);
$freebusy_req->setGroupExpansionMax(10);
$item = new Google_Service_Calendar_FreeBusyRequestItem();
$item->setId($email);
$freebusy_req->setItems(array($item));
$query = $cal->freebusy->query($freebusy_req);
$response_calendar = $query->getCalendars();
$busy_obj = $response_calendar[$email]->getBusy();
But I am getting blank in terms of free busy.

Just make sure the calendar is public, then try google calendar freebusy method. It will definitely work.

Related

Google.Cloud.AppEngine.V1 client libraries and traffic splitting in .NET

I am trying to use the Client Libraries provided by Google to move traffic from one version of an app in AppEngine to another. However, the documentation for doing this just talks about using the rest API and not the client libraries.
Here is some example code:
var servicesClient = Google.Cloud.AppEngine.V1.ServicesClient.Create();
var updateServiceRequest = new UpdateServiceRequest();
updateServiceRequest.Name = "apps/myProject/services/myService";
var updateMask = new Google.Protobuf.WellKnownTypes.FieldMask();
updateServiceRequest.UpdateMask = updateMask;
// See below for what should go here...
var updateResponse = servicesClient.UpdateService(updateServiceRequest);
My question is what format do I use for the update mask?
According to the documentation I should put in:
split {"split": { "allocations": { "newVersion": 1 } } }
But when I try: updateMask.Paths.Add(#"split { ""split"": { ""allocations"": { ""myNewVersion"": 1 } } }");
... I get the exception:
"This operation is only supported on the following field(s): [labels, migration_config, network_settings, split, tag_to_target_map], but got field(s): [split { "split": { "allocations": { "myNewVersion": 1 } } }] from the update request.
Any ideas where I should put the details of the split in the field mask object? The property Paths just seems to be a collection of strings.
The examples for these libraries in Google's doco is pretty poor :-(
I raised a support ticket with Google and despite them suggesting a solution which didn't work exactly (due to trying to assign a string to the UpdateMask which needs a FieldMask object), I managed to use it to find the correct solution.
The code should be:
// appService is a previously retrieved Service object from the ListServices method
var updateServiceRequest = new UpdateServiceRequest();
updateServiceRequest.Name = appService.Name;
updateServiceRequest.UpdateMask = new Google.Protobuf.WellKnownTypes.FieldMask();
updateServiceRequest.UpdateMask.Paths.Add("split");
appService.Split.Allocations.Clear();
appService.Split.Allocations["newServiceVerison"] = 1;
updateServiceRequest.Service = appService;

Azure AD Graph API issue: Specified $skiptoken is invalid

I get the following exception when trying to fetch AAD group transitive members using the Graph API:
Specified $skiptoken is invalid.
Here is my code:
private IEnumerable<Microsoft.Graph.User> GetGroupMembers(AccessLevel al) {
var usersCollectionPage = AsyncHelper.RunSync(() => Client.Groups[al.Id].TransitiveMembers.Request().GetAsync());
foreach (var user in usersCollectionPage.CurrentPage.OfType<Microsoft.Graph.User>()) {
yield return user;
}
while (usersCollectionPage.NextPageRequest != null) {
var page = usersCollectionPage;
usersCollectionPage = AsyncHelper.RunSync(() => page.NextPageRequest.GetAsync());
foreach (var user in usersCollectionPage.CurrentPage.OfType<Microsoft.Graph.User>()) {
yield return user;
}
}
}
It fails on page.NextPageRequest.GetAsync().
I am using Microsoft.Graph version 4.11.
This used to work. I suspect it stopped working after upgrading the Graph SDK.
The issue happens in a production environment where there are enough group members to trigger paging.
Has anyone else seen the issue?
This was fixed in Microsoft.Graph.Core 2.0.7: https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/345

laravel dusk facebook web driver and cookies

i was trying to login to a site with facebook chrome driver
and then visit another path of the website after login
login is successful but when I try to view another page
it dont recognize my login
here is my code :
$process = (new ChromeProcess)->toProcess();
$process->start();
$options = (new ChromeOptions)->addArguments(['--disable-gpu', '--headless','--enable-file-cookies','--disable-web-security','--allow-file-access-from-files']);
$capabilities = DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = retry(5, function () use ($capabilities) {
return RemoteWebDriver::create('http://localhost:9515', $capabilities);
}, 50);
$browser = new Browser($driver);
$browser::$baseUrl = 'https://example.com';
$browser->visit('/login')
->type('username','1375344')
->type('password','23444')
->press('.login_btn');
$browser->waitForText('welcome');
$browser->visit('/statement/deposit/view');
$browser->dump();
does laravel dusk and/or facebook driver has something like cookiejar?
Try
$browser->loginAs(User::find(1));
Additionally you can look at
Dusk Authentication

How to POST data to an online table without credentials

I have an HTML page that produces data (a table row). I want to store rows from all clients in an online table which can be accessed/downloaded (preferably by the owner alone, so anonymous clients can only add rows)
Possible solutions and encountered problems:
Google spreadsheet + google apps script - How to do a cross origin POST request?
Google fusion tables - How to add rows from anonymous clients? Is that possible?
Google app engine - possible, but seems too time consuming for this simple task.
I've found an answer on how to do cross domain POST, so I've managed to do what I want with apps script + spreadsheet:
Apps script:
function doPost(request) {
var ss = SpreadsheetApp.openById(id);
var sheet = ss.getSheets()[0];
if (request.parameters.row != null) {
sheet.appendRow(Utilities.jsonParse(request.parameters.row));
}
}
Client javascript (from https://stackoverflow.com/a/6169703/378594):
function crossDomainPost(paramsDict, url) {
// Add the iframe with a unique name
var iframe = document.createElement("iframe");
var uniqueString = "SOME_UNIQUE_STRING";
document.body.appendChild(iframe);
iframe.style.display = "none";
iframe.contentWindow.name = uniqueString;
// construct a form with hidden inputs, targeting the iframe
var form = document.createElement("form");
form.target = uniqueString;
form.action = url;
form.method = "POST";
// repeat for each parameter
for (i in paramsDict) {
var input = document.createElement("input");
input.type = "hidden";
input.name = i;
input.value = paramsDict[i];
form.appendChild(input);
}
document.body.appendChild(form);
form.submit();
}
crossDomainPost({'row': JSON.stringify([123, 123, 1211])}, serverURL);
Note that a similar scheme should work for Google fusion tables.

YouTube API Resumable Uploader Session Token

I am working with the YouTube api trying to upload a video using the resumable uploader. I would really rather not have to directly ask the user for their credentials.
I am able to use AuthSub and get a session token. The problem is I cant seem to use this with the resumable uploader. Is this possible or is this totally separate? I see that GDataCredentials can take a client token. What is this? I i use the session token I get back Error = {"The remote server returned an error: (401) Unauthorized."}
Here is my code
Video newVideo;
var mResumableUploader = new ResumableUploader(10485760);
mResumableUploader.AsyncOperationCompleted += mResumableUploader_AsyncOperationCompleted;
mResumableUploader.AsyncOperationProgress += mResumableUploader_AsyncOperationProgress;
var youTubeAuthenticator = new ClientLoginAuthenticator(AppName, ServiceNames.YouTube, new GDataCredentials(YouTubeToken));
youTubeAuthenticator.DeveloperKey = DevKey;
newVideo = new Video();
newVideo.Title = "video";
newVideo.Tags.Add(new MediaCategory("Entertainment", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "video";
newVideo.Description = "video";
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/mp4");
var link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads");
link.Rel = ResumableUploader.CreateMediaRelation;
newVideo.YouTubeEntry.Links.Add(link);
mResumableUploader.InsertAsync(youTubeAuthenticator, newVideo.YouTubeEntry, "inserter");
ClientLogin is problematic and will be deprecated soon. Please use OAuth2 and you won't have problems.

Resources