Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Blogger-设置将来发布条目的日期_Php_Google Api_Blogger_Google Api Php Client - Fatal编程技术网

Php Blogger-设置将来发布条目的日期

Php Blogger-设置将来发布条目的日期,php,google-api,blogger,google-api-php-client,Php,Google Api,Blogger,Google Api Php Client,我假设我使用以下代码来添加一篇新文章。如何设置公开发布的日期 <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository * @copyright Copyright (c) 2005-2015 Zend Technol

我假设我使用以下代码来添加一篇新文章。如何设置公开发布的日期

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application\Controller;
set_time_limit (300);

use Zend\View\Model\ViewModel;
use Zend\Mvc\Controller\AbstractActionController,
    Zend\Console\Request as ConsoleRequest;

use Zend\Http\Request;
use Zend\Http\Client;
use Zend\Http\Cookies;
use Zend\Http\Header;
use Zend\Stdlib\Parameters;
use Zend\Json\Json;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
$client = new \Google_Client();
$redirectUri='http://czystyping.dev/application/index/index';$client->setRedirectUri($redirectUri);
//$scriptUri = "http://".$_SERVER["HTTP_HOST"];///.$_SERVER['PHP_SELF'];$client->setRedirectUri($scriptUri);
$client->setAccessType('online'); // default: offline
$client->setApplicationName('Blogspot');
//$client->setAuthConfigFile('Blogspot-b4ae4.json');
$client->setClientId('st.apps.googleusercontent.com');
$client->setClientSecret('my-secret-string');
$client->setDeveloperKey('INSERT DEV HERE'); // API key
$client->setScopes("https://www.googleapis.com/auth/blogger");
$service = new \Google_Service_Blogger($client);


if(isset($authUrl)) {
    print "<a class='login' href='$authUrl'>Connect Me!</a>";
  } else {
   print "<a class='logout' href='?logout'>Logout</a>";
  }
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

    //var_dump($_GET['code']);
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    //$_SESSION['access_token'] = $client->getAccessToken(); 

        // Once the access token is retrieved, you no longer need the
        // authorization code in the URL. Redirect the user to a clean URL.
        //header('Location: '.filter_var($redirectUri, FILTER_SANITIZE_URL));
        //die();

}
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;
}
$blog      = $service->blogs->getByUrl('http://tapetoposty.blogspot.com/');
$blogName  = $blog->getName();
$blogUrl   = $blog->getURL();
$postsObj  = $blog->getPosts();
$postCount = $postsObj->getTotalItems();
$posts     = $postsObj->getItems();
$blogID  = $blog->getID();

$newpost = new \Google_Service_Blogger_Post();
$newpost->setTitle("2 Example post from zend");
$newpost->setContent("This is test content 3");
$newpost->setLabels(array('3d', 'blog z tapetami', 'do', 'hd', 'komputer', 'krajobrazy', 'lato', 'pulpit', 'tapeta', 'tapetoblog', 'tapety', 'tło', 'windows', 'wodospad', 'zdjęcia', 'zwierzęta', 'świąteczne'));
//$newpost->setUrl('example-url');
$newpost->setPublished('true'); //make Google_Service_Exception in /vendor/google/apiclient/src/Google/Http/REST.php:79 Message: Error calling POST https://www.googleapis.com/blogger/v3/blogs/1534947238029354603/posts?key=INSERT+DEV+HERE: (400) Invalid value for: Invalid format: "true"


//$newpost->setImages($images);
//$newpost->setTitleLink('title-link-example'); //make Google_Service_Exception
//  $newpost->setCustomMetaData($customMetaData); //untested
$post = $service->posts->insert($blogID, $newpost, array());


print_r($post);
导致错误ok,帖子立即发布。也许我需要使用SetCustomMetadata($customMetaData)才能正常工作?但我不知道如何构建$customMetaData(正如我在GoogleDocs OAuth游乐场上看到的那样,设置了作者和发布日期)


Edit2:感谢@abraham纠正我的错误,因为我没有使用翻译。

javadoc
中所述,对于
Google\u服务\u Blogger\u Posts\u Resource::publish()
方法:

@opt_param string publishDate可选择的日期和时间来安排 博客的发布。如果未提供publishDate参数,则post为 在以前保存的计划日期(如果存在)发布,或 当前时间。如果给出了未来的日期,该职位将被安排为 出版

因此,
Google\u Service\u Blogger\u Post::setPublished($pubDate)
方法要求字符串日期参数具有
RFC 3339
格式,使用所需日期发布的正确方式如下:

$date = new DateTime('+17 day'); 
$newpost->setPublished($date->format(DateTime::RFC3339));

javadoc
中所述,对于
Google\u Service\u Blogger\u Posts\u Resource::publish()
方法:

@opt_param string publishDate可选择的日期和时间来安排 博客的发布。如果未提供publishDate参数,则post为 在以前保存的计划日期(如果存在)发布,或 当前时间。如果给出了未来的日期,该职位将被安排为 出版

因此,
Google\u Service\u Blogger\u Post::setPublished($pubDate)
方法要求字符串日期参数具有
RFC 3339
格式,使用所需日期发布的正确方式如下:

$date = new DateTime('+17 day'); 
$newpost->setPublished($date->format(DateTime::RFC3339));

嗯,
$newpost->setPublished(newdatetime('NOW')?不幸的是,给定的解决方案不起作用。问题仍然有效。如果使用了
newdatetime('NOW')
,会弹出什么错误?或者只是
“现在”
?没有错误,只是正常执行。请参阅有问题的Edit1。您希望博主在将来显示文章的发布日期吗?但是,这是什么意思呢?或者,你想让那篇文章在延迟17天之后才出现在博客上?或者,您想在实际发布之前对已创建的
$newpost
执行某些操作?需要一些解释。嗯,
$newpost->setPublished(newdatetime('NOW'))?不幸的是,给定的解决方案不起作用。问题仍然有效。如果使用了
newdatetime('NOW')
,会弹出什么错误?或者只是
“现在”
?没有错误,只是正常执行。请参阅有问题的Edit1。您希望博主在将来显示文章的发布日期吗?但是,这是什么意思呢?或者,你想让那篇文章在延迟17天之后才出现在博客上?或者,您想在实际发布之前对已创建的
$newpost
执行某些操作?我需要一些解释。