July 29, 2011

How to add tags/labels to bloggers posts via Gdata api





<?php

/*
Posted at technoslab.blogspot.com
How to post to blogger using PHP with labels/categories/tags using gData api ?
*/

function createPublishedPost($title, $content,$tags){

/* DEFINE THESE */

$user = 'BLOGGER_USERNAME';
$pass = 'BLOGGER_PASS';
$blogID = 'YOUR_BLOG_ID';

$service = 'blogger';

    require_once'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_Query');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null,
              Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
              Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
    $gdClient = new Zend_Gdata($client);

  $uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
  $entry = $gdClient->newEntry();
  $entry->title = $gdClient->newTitle($title);
  $entry->content = $gdClient->newContent($content);
  $entry->content->setType('html');
  $tags = explode(",",$tags);
  if(is_array($tags)){
    $labels = array();
    foreach($tags as $tag){
        $labels[] = $gdClient->newCategory(trim($tag), 'http://www.blogger.com/atom/ns#');
    }
/* Adding tags to post */
    $entry->setCategory($labels);

    }
  $createdPost = $gdClient->insertEntry($entry, $uri);
  $idText = split('-', $createdPost->id->text);
  $newPostID = $idText[2];

  return $newPostID;
}





/* USAGE OF THIS FUNCTION */

createPublishedPost("Sample post title","I'm an a post the demonstrates usage of gdata api to publish articles to a blogspot blog.","sampletag1,sampletag2");

// tags must be passed to function as comma separated values.

?>


Dependency: http://framework.zend.com/download/gdata

Previous post on this: http://technoslab.blogspot.com/2011/04/posting-to-bloggercom-via-php.html

30 comments:

  1. Thank you for this example. After hours of searching it seems you are the only one in the world who has a working example on how to add labels to blogger post.
    Thank you very much.

    ReplyDelete
  2. When we choose to do the opposite of nothing, then we can do something to help others and
    make a difference. If you are unable to sign in to
    Game Center or are having problems staying connected:.
    You can only acquire a small amount of in-game money or gold,
    and cannot participate in the auction house, send mail, join guilds, or even whisper to someone unless someone whispers to you first.


    Feel free to surf to my blog - Customer-experience.ru

    ReplyDelete
  3. Major follows some sports, primarily during the playoffs.
    The player who spins the coin is referred to as the spinner.
    Making your game play is the next phase you'll be focusing on.

    Also visit my web page; cinemaextreme.blogspot.co.uk/2007/10/hairspray.html

    ReplyDelete
  4. Multiplayer versions is more exciting as in this, you'll be able to team up or even contend with other participants to defeat the enemies. they simply need to learn that you will not be able to appease everyone of your player-base. It is recommended that the golfers select those putters with which the golfers feel good and works well with their gaming pattern.

    Feel free to visit my webpage :: please click the following internet site

    ReplyDelete
  5. But, internet radio offers a whole lot more
    than just your favorite music online. We definitely
    like it's simple, clean black styling, push-button central dial and nicely labeled front controls, and the way that stations have sounded as we. The banner ad may be placed on the same page listeners go to when they want to listen to the station on-line.

    Feel free to visit my web-site - internetradio aussetzer

    ReplyDelete
  6. One of the other types of console where you can play this game
    is the fighting online video game. With some game clients are growing,
    web games will ensure players enjoy the same quality, and eventually catch up with the client
    game in the image. 4) As people showed up to vote KEEP, they
    were frequently branded "sockpuppets", banned, and their comments stricken from the discussion.


    Here is my site ... spiele spielen

    ReplyDelete
  7. Camping first aid kits are different from the first aid kits you may have at home, as they will be stocked with supplies to treat
    outdoor injuries, such as snakebite, burns, sprains as well as animal and insect bites.
    Once you decide what kind of Oregon coast camping vacation
    you are looking for, finding an Oregon coast camping site is a piece
    of cake. What I loved the most about these types of adventures was what
    I could see.

    Here is my page - click the up coming web site

    ReplyDelete
  8. With internet radio, you get pretty much what you want,
    when you want. Wi - Fi internet radio is a new
    handy device for all music lovers of this world, which is a gift of the
    technology to the entertainment world. You can see if any of your Facebook friends are listening
    by clicking on the Facebook link on the bottom right.


    Feel free to visit my blog post ... visit my webpage

    ReplyDelete
  9. The Nokia N8 provides an exciting alternative to
    some of the mainstream Smartphones which are currently available.
    If the horse is a good model and stands well during his photo op,
    then work it. This often enables consumers to review each
    camera individually to get all the details and find out what is
    included with their purchase.

    my web site Nikon digital Camera auctions

    ReplyDelete
  10. Wallace explained the importance of nature by explaining the relationship between the
    Man and Nature. These are reaching thousands of people at a
    time who recognize the self help benefits and pass them
    on to friends who do the same and they become viral. So choose
    the perfect Funny Family Poems to surprise your mother and
    make it a special memory to always remember.

    ReplyDelete
  11. You don't need to take my word for this, you can read the reviews for yourself. This 12 megapixel camera is capable of capturing 3D photos too. The software is Sony's "Picture Motion Browser" v
    5.

    my weblog: Read This method

    ReplyDelete
  12. They want to win by playing their very best as opposed
    to winning by putting the other person off. This means to sell your mods would be considered
    the same as pirating the game itself. In addition, you can save the effort
    of coding the store functionality, virtual goods dependencies, billing interfaces and rewards.


    my web site ... Learn Alot more Here

    ReplyDelete
  13. This idea would be perfectly done with camping, it allows a
    camper to acquire the utmost relaxation which is the basic objective
    of the activity. As one might have guessed, Si's little nap turns into an overnight stay at Phil and Kay's.
    Even though most liquid fuel stoves are more powerful and provide great
    heat output than canister stoves, they are not as convenient.


    Here is my website Comments On: Get More Vacation For Your Money! Go Camping

    ReplyDelete
  14. It iis based on computer with electrographic sensor technology.
    At the same time, web games seemed like the future of gaming, and we
    wanted to be a part of it. The main reason why you would want to do this is simple, you can unlock the true potential of your purchase.



    my page http://www.akiba.net/index.php?document_srl=729&mid=twitter **

    ReplyDelete
  15. (Game scheduled for December 15th with Utah State playing Toledo).
    It is an adventurous game filled with fun and excitement.
    Most video game testers reported that their salary falls between $15,000 and $55, 000 in a year.


    Here is my website :: simply click the following website page

    ReplyDelete
  16. The internet is fueling the success of music because it can be listened to at any time
    of the day and anywhere in the world. And once you have your own project
    that you want to promote, you must have considered the radio as one of the best alternatives
    to introduce your music to the crowds. You will need an outside antenna to get clear reception on your radio.


    My site - Radio Philips ae 2730

    ReplyDelete
  17. Dominion: Intrigue is a standalone expansion for the award-winning Dominion card game that shook the gaming world in 2008.
    By obtaining increasingly more favour using their company people in your social settings,
    the more handle you will need to acquire what you would like, and thru The particular Coalition Game you
    have just about the most effective tips for hypnotherapy that gives you the talent to ensure that you influence
    other folks. It sounds like you log into the game and join a "Shadow war" server and
    play with hundreds of other players within that PVP world, but that world is different from the cooperative Arkfall boss hunting world.


    Stop by my weblog ... Going in voice.mynewtestsite.
    eu []

    ReplyDelete
  18. In other trick taking games, players can take tricks on a number of kind of contract.

    Leveling up to defeat all the enemies can be
    time arresting so apprehend to absorb a acceptable bulk of
    hours anniversary day accepting the a lot
    of out of this game. Moreover, there you could also play Scrabble in the
    internet, TV game shows or game consoles.

    my page ... spielespielen24.de

    ReplyDelete
  19. What is the most important portion is the sincere words that you put together in the poems that will catch the attention of the one you loved as this is what you truly want
    from the romantic poems that you have created for him.
    Love poems intensify the feeling of love in the minds of lovers.
    So choose the perfect Funny Family Poems to surprise your mother
    and make it a special memory to always remember.

    my blog :: poems

    ReplyDelete
  20. Even though your goal is just to lose 5 pounds in a week,
    you should be strict with what you do so as not to inadvertently undo all your hard work for vegetarian
    weight loss. Anyone who dares to make a closer
    inspection will find the underlying difference. The institution
    has persistently offered ideal programs and services for those struggling to achieve certain levels of body weight.


    My blog post - visit the next site :: http://www.myunfinishedbusiness.com/index.php/member/25319 ::

    ReplyDelete
  21. Once you have the centers prepared, there are a number of ways to decorate the outside.

    If you prefer to use frozen strawberries, they work in this cake equally as well as
    the fresh. The TV crew will embark on the task of
    helping "sweet" businesses survive and prosper.

    my weblog :: diaper cake accessories ()

    ReplyDelete
  22. clients, Rachel, who got back together with
    her ex. At the same time, web games seemed like the future of gaming, and we wanted to be
    a part of it. Preparing to apply to the dozens of other game development companies for video game jobs will enable you to expand and diversify your list of possible employers, and your chances of getting hired will increase tremendously.


    my webpage :: university of colorado :: ::

    ReplyDelete
  23. Wallace explained the importance of nature by explaining the relationship between the Man and Nature.

    From ancient Britain come romantic love poems ** of forbiddin trysts in black forests
    and aristocratic romance between knights and fair maidens.

    On the other hand children spend most of their time with their mothers, who love deeply, scold harshly,
    they worry extremely but in the end they make you what you are.

    ReplyDelete
  24. Hey there! I've been reading your web site for a long time now and finally got the courage to go ahead and give you a shout out from Atascocita Texas! Just wanted to mention keep up the good job!


    http://gamersadda.org/index.php?do=/blog/125461/raspberry-ketone-reviews/

    my web site raspberry ketone review

    ReplyDelete
  25. I wanted to thank you for this good read!! I certainly enjoyed
    every bit of it. I've got you book-marked to look at new stuff you post…

    Here is my site :: cidp

    ReplyDelete
  26. Following, the rectus abdominus displaced the a mnemotechnical.
    Abs after pregnancy can be too to be your master tread-wheel physical exertion for free weight loss,
    support these three tonalities in mind. We experience all for most men
    to physique muscle; let lonely abs women. Wash the orbs of
    your feet as much as possible.

    My web blog - truth about abs - http://truthaboutabsdon.
    com ()

    ReplyDelete
  27. I for all time emailed this blog post page to all my
    associates, because if like to read it next my friends will too.


    Feel free to visit my web blog :: sawmilling

    ReplyDelete
  28. In other trick taking games, players can take tricks on a number of kind of contract.
    Leveling up to defeat all the enemies can be time arresting so apprehend
    to absorb a acceptable bulk of hours anniversary day
    accepting the a lot of out of this game. It sounds
    like you log into the game and join a "Shadow war" server and play with
    hundreds of other players within that PVP world,
    but that world is different from the cooperative Arkfall boss hunting world.


    my page sub zero ()

    ReplyDelete
  29. Music streaming on the Internet is usually referred to as webcasting since it is not transmitted broadly through wireless means.
    Hollywood 27 is first and foremost a film company, but recently it has ventured into broadcasting music
    of various genres via the popular platform Live365.
    There are sophisticated Wi-fi Internet radios available now, which are available complete with
    speakers, are portable and do not require a computer.

    My blog post - internetradio aufnehmen **

    ReplyDelete