使用Blogger PHP API v 3.0发布带有标签和搜索说明的Blogger

问题描述 投票:2回答:2

我想发布带有标签和搜索说明的Blogger。我从谷歌https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Blogger.php获得了一个链接

    $scriptUri = "https://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
    require_once 'google-api-php-client-master/src/Google/autoload.php'; 

    $client = new Google_Client();
    $client->setApplicationName("BloggerAPI");
    $client->setDeveloperKey("AIzaSysdCMlzJM2SsdxuEEdS-l9r2MxLgcfxylE2Bzc");

    $client->setAccessType('online');
   $client->setClientId("699839154993-7423kasdsdeibmi00ss1bk94plu5gi7ioene.apps.googleusercontent.com");
    $client->setClientSecret("82cVvhOy5z3hsW2Ur4fgdfg8QXaBR");
   $client->setRedirectUri($scriptUri);
    $client->setScopes(array('https://www.googleapis.com/auth/blogger')); //since we are going to use blogger services

    $bloggerService = new Google_Service_Blogger($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($_GET['code']);
        $_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;
    }

    $posts = $bloggerService->posts;

    $NewPost = new Google_Service_Blogger_Post();
    $NewPost->setTitle("Post Title ".time());
    $NewPost->setLabels("Post Label1");
    $NewPost->setContent("Post Content!!!!");
    $NewPost->setCustomMetaData("Custom Meta Data ".time());

    try
    {
    $nposts = $posts->insert("310034677540144362",$NewPost);
    }
    catch(Exception $e)
    {
       print_r($e);
    }

在这篇文章之后,我登录了博客。我可以在那里看到上面的帖子。这篇文章有'Post Title'和'Post Body',但它没有'标签'和'搜索描述'。

enter image description here我如何发布'标签'和'搜索描述'?

可能吗?

php api blogger google-api-php-client
2个回答
0
投票

目前无法发布或获取搜索说明。我已经对整个API进行了几次搜索并且没有提出任何问题。我认为搜索词实际上并不与Blogger对象相关联,即它是Blogger的独立功能。伤心。 。 。


-2
投票

你应该使用:

$NewPost = new Google_Service_Blogger_Post();
$NewPost->setLabels(array('Label1', 'Label2'));
© www.soinside.com 2019 - 2024. All rights reserved.