Создание сообщений на Blogspot автоматически

Здравствуйте! Я пытаюсь разработать функцию, которая будет публиковать сообщения в моем блоге в коде без какого-либо разрешения или действия со стороны средства просмотра веб-сайта.

Мне нужно отправить два параметра: заголовок и содержание сообщения.

Мы можем назначить эти $ title и $ content

Я работаю и исследую это около 2 недель. Документация о том, как это сделать, практически отсутствует, а существующая документация устарела и очень сложна в использовании.

Любая помощь будет с благодарностью.

Мне удалось правильно настроить мой ключ API с помощью открытого ключа Blogger V3 API. Я получаю действительный возврат данных JSON, хотя мне просто нужно знать, как создавать сообщения.

Спасибо!

<?php

function file_get_contents_curl($url) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);

$data = curl_exec($ch);
curl_close($ch);

return $data;
}$blogID = '2139447653782748476';
$apikey = '***';

$requestURL = "https://www.googleapis.com/blogger/v3/blogs/{$blogID}?key={$apikey}";

//$requestURL = "http://icanhazip.com";

//$json = file_get_contents("http://icanhazip.com");

$json = file_get_contents_curl($requestURL);

$json = json_decode($json);

//echo $requestURL;

//var_dump($json);

var_dump($json);

//echo $json;

?>

Второй код, который я попробовал:

<?php
/*
function file_get_contents_curl($url) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);

$data = curl_exec($ch);
curl_close($ch);

return $data;
}if ($_GET['key'] != 'buswell') {
die();
}
/*
$blogID = '2139447653782748476';
$apikey = 'AIzaSyDbouGxlQ9P9JMuH4SJlq43xMhyVGWe14g';

$requestURL = "https://www.googleapis.com/blogger/v3/blogs/{$blogID}?key={$apikey}";

//$requestURL = "http://icanhazip.com";

//$json = file_get_contents("http://icanhazip.com");

$json = file_get_contents_curl($requestURL);

$json = json_decode($json);

//echo $requestURL;

//var_dump($json);

var_dump($json);

//echo $json;

*/

session_start();
require_once dirname(__FILE__).'/google-api-php-client-master/src/Google/Client.php';
require_once dirname(__FILE__).'/google-api-php-client-master/src/Google/Service/Client.php';

$scriptUri = "http://connectionincognito.com/dev.php";

$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('giaws'); //name of the application
$client->setClientId('924143111807-63s8j0f8rnn7ps3pdtnah827rvj29mnr.apps.googleusercontent.com'); //insert your client id
$client->setClientSecret('77c9742276a14988db77f8b5454f9ba378762246'); //insert your client secret
$client->setRedirectUri($scriptUri); //redirects to same url
$client->setDeveloperKey('77c9742276a14988db77f8b5454f9ba378762246'); // API key (at bottom of page)
$client->setScopes(array('https://www.googleapis.com/auth/blogger')); //since we are going to use blogger services

$blogger = new Google_BloggerService($client);

if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}

if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}

if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}

if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
//you can get the data about the blog by getByUrl
$data = $blogger->blogs->getByUrl(array('url'=>'http://proxies-unlimited.blogspot.com/'));

//creates a post object
$mypost = new Google_Post();
$mypost->setTitle('this is a test 1 title');
$mypost->setContent('this is a test 1 content');

$data = $blogger->posts->insert('2139447653782748476', $mypost); //post id needs here - put your blogger blog id
var_dump($data);
?>

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector