Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 从userID获取学生电子邮件_Python 3.x_Api_Google Classroom - Fatal编程技术网

Python 3.x 从userID获取学生电子邮件

Python 3.x 从userID获取学生电子邮件,python-3.x,api,google-classroom,Python 3.x,Api,Google Classroom,我已经能够成功地从课堂上获取课程和学生提交列表 我现在想获取学生的电子邮件地址,而不是使用studentsubmission返回的用户ID。 非常有用的说法是使用userProfiles.get,因此使用此行= studentEmail = service.userProfiles().get(userId = student['userId']) 这将导致以下输出: <googleapiclient.http.HttpRequest object at 0x0000000003F9C0

我已经能够成功地从课堂上获取课程和学生提交列表

我现在想获取学生的电子邮件地址,而不是使用studentsubmission返回的用户ID。
非常有用的说法是使用userProfiles.get,因此使用此行=

studentEmail = service.userProfiles().get(userId = student['userId'])
这将导致以下输出:

<googleapiclient.http.HttpRequest object at 0x0000000003F9C048> TURNED_IN
但这似乎不起作用,而且文档对我来说有点模糊

提前谢谢

编辑***

做了一些更改,所以我的循环现在看起来像这样 students=studentSubmissionResults.get('studentSubmissions',[])


这导致了范围不足错误,但我在userProfile.get()页面上提供了所有建议的范围

从文档中可以看出,您应该使用

.get('emailAddress')
根据
userProfiles.get(userId)
调用的结果


此外,您应该将此调用包装在
try except
块中,以处理请求中的失败。

这就是我的想法,但我尝试的任何组合似乎都以“object has not attribute”错误结束。因此,我做了一些更改,将Pedro标记为正确,因为它是对结果的get(),并进行了一些范围更改。然后我不得不重新授权,以允许范围的更改。
for student in students:
    studentId = service.userProfiles().get(userId = 
                student['userId']).execute()
    studentEmail = studentId.get('emailAddress').execute()
    assignmentState = student['state']
    print('The following students have completed the work:\n', studentEmail 
           , assignmentState )
.get('emailAddress')