मैं जीमेल से ईमेल पढ़ने के लिए Google API क्लाइंट का उपयोग कर रहा हूं। अब मैं एक क्रोनबॉज जोड़ना चाहता हूं ताकि यह हर 5 मिनट में मेल पढ़ सके।Google API क्लाइंट और क्रोनबॉज
Google API क्लाइंट का उपयोग करने में समस्या यह है कि उपयोगकर्ता को प्राधिकरण लिंक पर पहली बार क्लिक करने की अनुमति देने और उपयोगकर्ता को Google API क्लाइंट का उपयोग करने की अनुमति देने की आवश्यकता है।
मेरे पास एक फ़ंक्शन इनबॉक्स है जिसमें एक फ़ंक्शन प्रारंभ होता है जो Google API क्लाइंट को initliazes करता है। लेकिन cronjob काम नहीं करता है क्योंकि मुझे access_token प्राप्त करना है।
public function initialize() {
$configuration = Configuration::getConfiguration('class_Inbox');
// Creates the Google Client
$this->client = new Google_Client();
$this->client->setApplicationName('Tiptsernetwork');
$this->client->setClientId($configuration['clientId']);
$this->client->setClientSecret($configuration['clientSecret']);
$this->client->setRedirectUri('http://www.tipsternetwork.nl/cronjob/authenticate');
$this->client->addScope('https://mail.google.com/');
$this->client->setApprovalPrompt('force');
$this->client->setAccessType('offline');
// Creates the Google Gmail Service
$this->service = new Google_Service_Gmail($this->client);
// Authenticates the user.
if (isset($_GET['code'])) {
$this->authenticate($_GET['code']);
}
// Check if we have an access token in the session
if (isset($_SESSION['access_token'])) {
$this->client->setAccessToken($_SESSION['access_token']);
} else {
$loginUrl = $this->client->createAuthUrl();
echo '<a href="'.$loginUrl.'">Click Here</a>';
}
// If the token is expired it used the refresh token to generate a new Access Token
if($this->client->isAccessTokenExpired()) {
$this->client->refreshToken($configuration['refreshToken']);
}
}
public function authenticate($code) {
// Creates and sets the Google Authorization Code
$this->client->authenticate($code);
$_SESSION['access_token'] = $this->client->getAccessToken();
$this->client->refreshToken($configuration['refreshToken']);
// Redirect the user back after authorizaton
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($url, FILTER_VALIDATE_URL));
}
क्या आप जानते हैं कि रीफ्रेश टोकन या जो भी हो, इसे ठीक करने के लिए इसे कैसे ठीक किया जाए? मैं इसे काम नहीं कर सकता और मैं विचारों से बाहर हूं।
मैं यूआरएल तक पहुँचने और "यहां क्लिक करें" और यह अनुमति देते हैं यह सफलतापूर्वक नहीं बल्कि एक cronjob क्योंकि मैं "यहाँ क्लिक करें" यूआरएल पर क्लिक नहीं कर सकते हैं के साथ काम करता पर क्लिक कर रहा हूँ तो ...
मुझे आशा है कि आप लोग इसे समझते हैं और मेरी मदद कर सकते हैं :)।
सधन्यवाद,
Yanick