コード例 #1
0
 public function connect_oauth2($connectObj)
 {
     $responseObj = $this->defaultResponseObj;
     // Lets first create a generic user with no email account
     $contextio = new ContextIO(CONTEXTIO_KEY, CONTEXTIO_SECRET);
     // Create the user
     $userParamsArray = array("email" => $connectObj["email"], "first_name" => $connectObj["firstName"], "last_name" => $connectObj["lastName"]);
     // ensure the user was created successfully
     $response = $contextio->addUser($userParamsArray);
     if (!is_object($response)) {
         // Fail
         $responseObj["Message"] = "Unable to add new user email accounts at this time. Try again later or contact us directly for additional assistance.";
         return $responseObj;
     } else {
         $rawResponse = json_decode($response->getRawResponse(), true);
         // Check for success
         if ($rawResponse["success"]) {
             // Use this to create a connect token
             $tokenParamsArray = array("callback_url" => "https://www.builtonfive.com/sharemail/api/v1/personalemail/save_connect_token", "email" => $connectObj["email"], "first_name" => $connectObj["firstName"], "last_name" => $connectObj["lastName"]);
             $response2 = $contextio->addConnectToken($tokenParamsArray);
             if (!is_object($response2)) {
                 // fail
                 $responseObj["Message"] = "Unable to connect to new email account at this time. Try again later or contact us directly if you need assistance.";
                 $responseObj["API_Response"] = $response2->getRawResponse();
             } else {
                 $rawResponse2 = json_decode($response2->getRawResponse(), true);
                 if ($rawResponse2["success"]) {
                     $responseObj["Success"] = true;
                     $responseObj["Message"] = "New email account has been added. Go to Personal Email to start sharing.";
                     $responseObj["RedirectUri"] = $rawResponse2["browser_redirect_url"];
                     $responseObj["Id"] = $rawResponse["id"];
                     $responseObj["Token"] = $rawResponse2["token"];
                     $responseObj["API_Response"] = $response2->getRawResponse();
                 }
             }
         }
         return $responseObj;
     }
 }