donglu8779 2015-08-22 00:53
浏览 235

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

I want to post to Blogger with label and search description. I got a link from google 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);
    }

After this post, then i logged into blogger. I can see the above post there. With this post has 'Post Title' and 'Post Body', but it has no 'label' and 'Search description'.

enter image description here How can i post with 'label' and 'Search description'?

Is it possible?

  • 写回答

2条回答 默认 最新

  • dongmei8511 2016-01-25 16:43
    关注

    You should use:

    $NewPost = new Google_Service_Blogger_Post();
    $NewPost->setLabels(array('Label1', 'Label2'));
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题