-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from sanjuktaghosh7/classroom-snippets
Classroom Snippets
- Loading branch information
Showing
8 changed files
with
122 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,37 +15,37 @@ | |
* limitations under the License. | ||
*/ | ||
// [START classroom_add_teacher] | ||
require __DIR__ . '/vendor/autoload.php'; | ||
use Google\Service\Classroom\Teacher; | ||
|
||
function addTeacher($service, $courseId, $teacherEmail) { | ||
$teacher = new Google_Service_Classroom_Teacher(array( | ||
'userId' => $teacherEmail | ||
)); | ||
try { | ||
// calling create teacher | ||
$teacher = $service->courses_teachers->create($courseId, $teacher); | ||
printf("User '%s' was added as a teacher to the course with ID '%s'.\n", | ||
$teacher->profile->name->fullName, $courseId); | ||
} catch (Google_Service_Exception $e) { | ||
if ($e->getCode() == 409) { | ||
printf("User '%s' is already a member of this course.\n", $teacherEmail); | ||
} else { | ||
throw $e; | ||
$teacher = new Google_Service_Classroom_Teacher(array( | ||
'userId' => $teacherEmail | ||
)); | ||
try { | ||
// calling create teacher | ||
$teacher = $service->courses_teachers->create($courseId, $teacher); | ||
printf("User '%s' was added as a teacher to the course with ID '%s'.\n", | ||
$teacher->profile->name->fullName, $courseId); | ||
} catch (Google_Service_Exception $e) { | ||
if ($e->getCode() == 409) { | ||
printf("User '%s' is already a member of this course.\n", $teacherEmail); | ||
} else { | ||
throw $e; | ||
} | ||
} | ||
} | ||
return $teacher; | ||
} | ||
return $teacher; | ||
} | ||
|
||
/* Load pre-authorized user credentials from the environment. | ||
TODO(developer) - See https://developers.google.com/identity for | ||
guides on implementing OAuth2 for your application. */ | ||
require 'vendor/autoload.php'; | ||
$client = new Google\Client(); | ||
$client->useApplicationDefaultCredentials(); | ||
$client->addScope("https://www.googleapis.com/auth/classroom.profile.photos"); | ||
$service = new Google_Service_Classroom($client); | ||
// [END classroom_add_teacher] | ||
|
||
//method call | ||
addTeacher($service, '531365794650' ,'[email protected]'); | ||
|
||
addTeacher($service,'531365794650','[email protected]'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters