} class VKPoster { public function post($to, $message) { $credentialsPath = expandHomeDirectory('~/.config/email-to-vk-vk.json'); if (file_exists($credentialsPath)) { $accessToken = file_get_contents($credentialsPath); } else { // Request authorization from the user. // Let's pretend we are IPad application 8-) $authUrl = 'https://oauth.vk.com/authorize?client_id=3682744&v=5.7&scope=wall,offline&redirect_uri=http://oauth.vk.com/blank.html&display=page&response_type=token'; printf("Open the following link in your browser:\n%s\n", $authUrl); print 'Enter access token: '; $accessToken = trim(fgets(STDIN)); // Store the credentials to disk. if (!file_exists(dirname($credentialsPath))) { mkdir(dirname($credentialsPath), 0700, true); } file_put_contents($credentialsPath, $accessToken); printf("Credentials saved to %s\n", $credentialsPath); } return file_get_contents('https://api.vk.com/method/wall.post?owner_id=' . $to . '&from_group=1&message=' . urlencode($message) . '&access_token=' . $accessToken); } } $gmail = new MailParser(); $messages = $gmail->getEmails('*****@*****.**'); $vk = new VKPoster(); foreach ($messages as $m) { var_dump($vk->post(-104550496, $m)); }