2016-01-10 7 views
5

इसलिए मैंने quickstart मार्गदर्शिका का पालन किया और शेड्यूलर नामक कक्षा में इसे तोड़ने का फैसला किया। मैं प्रमाणीकरण कोड पर काम कर रहा हूं, लेकिन मुझे यह मिल रहा है: "त्रुटि 400 (OAuth 2 त्रुटि) त्रुटि अमान्य अनुरोध गुम आवश्यक पैरामीटर: redirect_uri"।Google क्लाइंट एपीआई - गुम होने की आवश्यकता पैरामीटर: redirect_uri

class scheduler{ 

//The Google Client object 
private $googleClient; 

//the Google Calendar Service ojbect 
private $calendarService; 

/* 
* Google Calendar Setup 
* 
* This creates a Google Client object so that you may create a Google Calendar object. 
* 
*/ 
function __construct(){ 
    //set the application name 
    define("APPLICATION_NAME", "Web client 1"); 
    // 
    define("CREDENTIALS_PATH", "~/scheduler/credentials.json"); 
    // 
    define("CLIENT_SECRET_PATH", __DIR__ . "/scheduler/client_secret.json"); 
    // 
    define("SCOPES", implode(" ", array(Google_Service_Calendar::CALENDAR_READONLY))); 

    /*if(php_sapi_name() != "cli"){ 
     throw new Exception("This application must be run on the command line");  
    }*/ 

    //create the google client 
    $this->googleClient = new Google_Client(); 

    //setup the client 
    $this->googleClient->setApplicationName(APPLICATION_NAME); 
    $this->googleClient->setDeveloperKey("AIzaSyBmJLvNdMYuFhVpWalkUdyStrEBoVEayYM"); 
    $this->googleClient->setScopes(SCOPES); 
    $this->googleClient->setAuthConfigFile(CLIENT_SECRET_PATH); 
    $this->googleClient->setAccessType("offline"); 

    //get the credentials file path 
    $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); 

    //if the file exists 
    if(file_exists($credentialsPath)){ 

     //get the credentials from the file 
     $accessToken = file_get_contents($credentialsPath); 

    }//if it does not 
    else{ 

     //request the authorization url 
     $authURL = $this->googleClient->createAuthUrl(); 
     //print the authorization ulr 
     echo "<a href=\"$authURL\">Press Me</a><br /><br />"; 

     //prompt the user to enter the auth code 
     print("Enter authentication code: "); 

     // 
     $authCode = trim(fgets(STDIN)); 

     //exchange authorization for an access token 
     $accessToken = $this->googleClient->authenticate($authCode); 

     //store credentials to disk 
     if(!file_exists(dirname($credentialsPath))){ 
      mkdir(dirname($credentialsPath), 0700, true); 
     } 

     //put the contents into the credential files 
     file_put_contents($credentialsPath, $accessToken); 
    } 

    $this->googleClient->setAccessToken($accessToken); 

    //refresh token if its expired 
    if($this->googleClient->isAccessTokenExpired()){ 
     $this->googleClient->refreshToken($client->getRefreshToken()); 

     file_put_contents($credentialsPath, $this->googleClient->getAccessToken()); 
    } 
} 

मुझे समस्या में कोई समाधान नहीं मिला समस्या का कारण मिला। मेरे Google डेवलपर कंसोल के तहत मैंने प्राधिकृत रीडायरेक्ट यूआरआई अनुभाग में "http://localhost/" डालने का प्रयास किया। यह मुझे यह त्रुटि देता है "क्षमा करें, एक समस्या है। अगर आपने जानकारी दर्ज की है, तो इसे जांचें और पुनः प्रयास करें। अन्यथा, समस्या स्वयं ही स्पष्ट हो सकती है, इसलिए बाद में जांचें।" क्या स्थानीय डेवलपर सर्वर के रीडायरेक्ट यूरी को स्वीकार करने के लिए Google डेवलपर कंसोल बनाने का कोई तरीका है?

+0

किसी की मदद करने के लिए तैयार? –

उत्तर

3

मुझे यह काम करने के लिए मिला। मुझे जो करना था वह Google डेवलपर कंसोल में वापस गया था और मैंने जो प्रोजेक्ट बनाया था उसे हटा दिया था। फिर एक नई परियोजना बनाते समय मुझे अपने लोकहोस्ट यूआरएल को बचाने की अनुमति दी गई। यह मुद्दा था कि जब मैं अपने स्थानीयहोस्ट यूआरएल को रीडायरेक्ट यूआरएल में जोड़ने के लिए गया था तो यह कहता था कि इस समय यह संभव नहीं है। जब मैं बटन बनाने से पहले रीडायरेक्ट यूआरएल सेट करता हूं तो यह इसे ठीक से स्वीकार करता है।

+1

अपना समाधान पोस्ट करने के लिए धन्यवाद - मैं एक मौजूदा प्रोजेक्ट को संपादित करने में सक्षम था और एक अधिकृत रीडायरेक्ट यूआरआई जोड़ रहा था ... –

+0

कोई समस्या नहीं डेवलपर। मदद करने में खुशी। –

+4

इसका कारण यह है कि, क्योंकि आपके क्लाइंट गुप्त जेसन फ़ाइल को डाउनलोड करने की आवश्यकता है। तो यदि आप यूरी के बिना अपने क्रेडेंशियल बनाते हैं और जेसन डाउनलोड करते हैं, तो जेसन में 'redirect_uris' प्रॉपर्टी नहीं होती है। यदि आप जाते हैं और इसे डैशबोर्ड में जोड़ते हैं, तो आपको क्लाइंट गुप्त जेसन को फिर से डाउनलोड करना होगा और इसे अपनी प्रोजेक्ट में जोड़ना होगा। –

संबंधित मुद्दे