Can't get email from Google Classroom student profile - google-apis-explorer

I'm trying to write a PHP routine to import Google Classroom enrollment data into our database. Here are my scopes:
$client->setScopes([Google_Service_Classroom::CLASSROOM_COURSES_READONLY, Google_Service_Classroom::CLASSROOM_ROSTERS_READONLY, Google_Service_Classroom::CLASSROOM_PROFILE_EMAILS]);
Then I'm trying to run through the class enrollment data. (I made a class in my personal Google account, and got some co-workers to sign up for the class.) I'm getting profiles, but the emailAddress is always blank:
$results = $service->courses->listCourses();
foreach ($results->getCourses() as $course) {
$roster = $service->courses_students->listCoursesStudents($course->id);
foreach ($roster['students'] as $student) {
$profile = $student['profile'];
$name = $profile['name']; // Works
$first_name = $name['givenName']; // Works
$email = $profile['emailAddress']; // Always null
}
}
What am I missing?

This has mysteriously started to work...which does not make me feel great, but you know the feeling, right? There's no way to make the problem come back, so you just have to hope it doesn't...I will post here again if it does.
Maybe this is related to the fact that we just refilled the form with new scopes. So for the moment, I'm getting a warning that "Google hasn't verified the app" before it connects. So maybe it's the new scopes, or maybe it's the warning.

Related

Passing query strings from bot to html page

In Microsoft Bot Framework - botbuilder v.3.15.0
When opening url from bot without any query strings - it perfectly works - and opens external url (previously defined var urlExt, or just plain 'https://some.html') when clicking on a button in the bot... - in Bot Framework Emulator, Azure Web Chat, Messenger & Telegram - perfectly ok.
lib.dialog('/', [
function (session, args) {
args = args || {};
// var pkey1 = 'fdsa'; // dummy variable, url with querystring with this dummy works ok on all channels!
// var rkey1 = 'asdf'; // dummy variable, url with querystring with this dummy works ok on all channels!
var pkey1 = session.logger.address.conversation.id;
var rkey1 = session.logger.address.user.id;
console.log(pkey1); // correctly shows conversation id in console locally
console.log(rkey1); // correctly shows user id in console locally
var urlMap = `https://mymap.azurewebsites.net/?cid=${pkey1}&uid=${rkey1}`;
var urlExt = encodeURI(urlMap);
setTimeout(function () {
var addressCard = new builder.HeroCard(session)
.title('address_title')
.subtitle('address_subtitle')
.images([
new builder.CardImage(session)
.url('https://somedb.blob.core.windows.net/images/ab_small.png')
.alt('Here comes some pic')
])
.buttons([
builder.CardAction.openUrl(session, urlExt, 'Just do it!')
]);
session.send(new builder.Message(session)
.addAttachment(addressCard));
}, 1000)
},
function (session, results) {
// some further code
}
]);
But when you try to insert query string into urlExt - by taking it's parameters conversation.id and user.id from 'session' - by making variables who take values of conversation.id and user.id from 'session' and then inserting those variables into urlExt (either by '+' concatenation, or by `` ${} method) it works locally in Emulator - but not on Azure Web Chat or Messenger or Telegram.
When I try to find the reason for this problem I tried not to grab conversation.id or user.id from 'session', but just insert some dummy variables with text to forward them into html page by inserting those variables as part of the query string - IT WORKS...:(
Really strange, the problem seems to be with getting conversation.id & user.id from 'session' to variables at Azure Portal.
But why does it perfectly work locally on my laptop?
Logs on Azure say that:
TypeError: Cannot read property 'conversation' of undefined
I have looked in stackoverflow - there is ZERO info about it, I looked at the various code at GitHub - NO ANSWERS...
Please, hint, or help...
The session logger is only enabled on certain channels, which is why your code works in the emulator but not in Test in WebChat on Azure and Microsoft Teams. Instead of getting the conversation and user ids from the logger attribute, access them from the message property.
var pkey1 = session.message.address.conversation.id;
var rkey1 = session.message.address.user.id;
Hope this helps!

Webhook Listener for Eventbrite

I've been searching far and wide for samples of Webhook Listeners for Eventbrite. My goal is to implement it into amazon api gateway and lambda. I've seen many tutorials configuring the gateway, but no sample code for eventbrite.
Does anyone have anything for this?
I'm also looking for something similar, and I've stumbled in this article, which I think might be a good starting point: https://developers.exlibrisgroup.com/blog/Hosting-a-Webhook-Listener-in-AWS
It doesn't cover how to create an Eventbrite webhook listener specifically, but it should be enough to get you started.
I actually made a PHP listener last year that took the attendee.updated event and performed a lookup to get the updated attendee info. I used an API framework, so I'll just give you the most important bits you might be able to transpose for use with Lambda:
//Assuming $body is the webhook payload
$url = $body['api_url'];
$arr = explode('/',rtrim(substr($url,strpos($url,'events/')),'/'));
for($i=0; $i<count($arr); $i+=2) {
$parts[$arr[$i]] = $arr[$i+1];
}
Using eventbrite/eventbrite-sdk-php I created a wrapper class:
class Eventbrite {
const OAUTH_TOKEN = '(TOKEN)';
function __construct() {
$this->Client = new \HttpClient(self::OAUTH_TOKEN);
}
public function get_attendee($event = '(DEFAULT EVENT ID)',$id) {
$path = "/events/".$event."/attendees/".$id."/";
return $this->Client->get($path);
//return array($path);
}
public function get_order($order) {
$path = "/orders/".$order;
return $this->Client->get($path);
}
}
And then with that $parts array:
$Eventbrite = new Eventbrite();
$attendee = $Eventbrite->get_attendee($parts['events'],$parts['attendees']);
You then have all the attendee's registration information, status, etc., in the $attendee array, e.g. $attendee['profile']['first_name'].

EWS - FileAttachment Content is empty / byte[0]

I have written a WebAPI controller method that finds a mail by its unique ID from ExchangeOnline. I wrote a small model class in order to store some attributes of a mail like the subject, the sender, the date received and so on.
Now I also want to access file attachments if the mail has such attachments. Therefore, I wrote this code (just the relevant part):
List<AttachmentItem> attDataContainer = new List<AttachmentItem>();
EmailMessage originalMail = EmailMessage.Bind(service, new ItemId(uniqueID), new PropertySet(ItemSchema.Attachments));
foreach (Attachment att in originalMail.Attachments)
{
if (att is FileAttachment && !att.IsInline)
{
FileAttachment fa = att as FileAttachment;
fa.Load();
attDataContainer.Add(
new AttachmentItem
{
ID = fa.Id,
Name = fa.Name,
ContentID = fa.ContentId,
ContentType = fa.ContentType,
ContentLocation = fa.ContentLocation,
Content = Convert.ToBase64String(fa.Content),
Size = fa.Size
});
}
}
The method indeed finds the attachments and displays all of the attributes you can see in the "AttachmentItem" object - BUT NOT the fa.Content attribute.
I have crwaled almost any document I could find on this (especially the *.Load() part as well as much examples. But in my case I get "byte[0]" when debugging the output.
Do you have any idea for me what could be the reason for this?
PS: By the way, I have version v2.0.50727 of Microsoft.Exchange.WebServices referenced.
Best regards and thanks in advance,
Marco
When you call the load method on the Attachment that should make a GetAttachment request to the server which will return the data for that Attachment. If you enable tracing https://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx that should allow you to follow the underlying SOAP requests which should help with troubleshooting (eg you can see what the server is returning which is important).
The other thing to check is that is this is a real attachment vs a One Drive attachment which could be the case on ExchangeOnline.

Replace Video Resource with VIMEO API

I am trying to replace existing video on VIMEO with
advanced api from : https://github.com/vimeo/vimeo.php#replace-videos-from-the-server.
The code is:
$vimeo = new \Vimeo\Vimeo('xxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxx');
$vimeo->setToken("xxxxxxxxxxxxxxx");
$video_id_on_vimeo = 123456; // not real id
$vimeo->replace("/videos/" . $video_id_on_vimeo, $path_to_file, false);
However it throws me an error "Unable to get an upload ticket.[The requested user could not be found]'
All other commands do work. I am using OAUTH 2 and scopes configured for using apis are:
public private purchased create edit delete interact upload.
in order to run example, just execute POST request to http://panels.veedi.com/api/video/test
Vimeo development team fixed the bug.
Now everything is working. In addition in API description of replacement process, they have mistake.
Instead of:
$response = $lib->upload('/videos/12345', '/home/aaron/Downloads/ada.mp4', false);
You should use:
$response = $lib->replace('/videos/12345', '/home/aaron/Downloads/ada.mp4', false);

HTML5 localStorage + Twitter oAuth

I have a jQuery Mobile app that uses Twitter oAuth to handle login and registration. However iPhone Mobile apps that get added to the home screen doesn't handle sessions. I have been told I need to use localStorage. Here is my current code that I need help translating to localStorage rather than sessions. Any help would be much appreciated.
Main page:
<?php
require("lib/twitteroauth.php");
session_start();
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('consumer key','secret');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('login.php');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
if($twitteroauth->http_code==200){
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
header ('Location: '.$url);
} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
die('Something wrong happened.');
}
?>
After Twitter handles the login it redirects to login.php:
<?php
require("lib/twitteroauth.php");
session_start();
if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){
// TwitterOAuth instance, with two new parameters we got in twitter_login.php
$twitteroauth = new TwitterOAuth("consumer key", "secret",$_SESSION['oauth_token'],$_SESSION['oauth_token_secret']);
// Let's request the access token
$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);
// Save it in a session var
$_SESSION['access_token'] = $access_token;
// Let's get the user's info
$user_info = $twitteroauth->get('account/verify_credentials');
}
?>
Thanks!
This should help understand what you need to complete the task of saving to LocalStorage.
http://sixrevisions.com/web-development/html5-iphone-app/
nb: see section near end of the article on Offline Data