Using Yammer Open Graph in .NET – Part 1


I've already written about using the Yammer APIs from a .NET client application here:  http://blogs.technet.com/b/speschka/archive/2013/10/05/using-the-yammer-api-in-a-net-client-application.aspx.  This post is the next logical step in that journey, which is working with Yammer Open Graph items from .NET.  A little background is probably in order though, like what is this Yammer Open Graph thing and how or why would I use it?  Well, the Open Graph object in Yammer is in many ways kind of analogous to a placeholder representing some URL-addressable content.  For example, it could represent a web site, a document in SharePoint, or anything else that you can refer to by Url.

What's cool about Open Graph objects (OGO) is that you can have a full blown discussion associated with them, just like you would a Yammer group.  You can also Follow an OGO so you can be alerted to updates on it, and you can Share an OGO too.  Within the discussion area for an OGO you can also create all of your typical Yammer content – uploads, polls, praises, events and announcements.  Probably the biggest difference between an OGO and a Yammer group is that there isn't the same notion of security – there aren't public and private OGOs and you don't join them: you just choose to follow them or not.  Creating OGO also creates an entry in the user's activity stream as well, so they will see that when going to the Yammer home page.

From a data standpoint, what's also interesting about OGO is that they provide a much richer data structure than a typical Yammer group.  An OGO allows you to associate the Url I mentioned earlier, as well as an Actor (kind of like who owns this OGO); the OGO is then linked to the Actor's profile in Yammer.  Each OG write activity also includes an action – like Create, etc; in practice I've found that the Create and Update actions are the only ones that consistently do "something".  You can also associate one or more users with an Activity, which really just means that you can choose to notify them when you apply your OGO action.  In addition to the URL you can also provide a title, description and image for the OGO.

So with that bit of background on what an OGO is, let's talk about how one can actually work with it in a .NET application.  First, as I mentioned above, you want to start with the the code I included in my original post on using Yammer with .NET that I referenced above; all of my Yammer code just continues to build off of that.  I've added some new classes to serialize and deserialize the data for OGO in the sample application, and I've added those classes to the attachment for this post.  The object model I built for OGO then looks something like this:

– Open Graph Item

    – Activity

        – Actor

            – Name

            – Email

        – Action

        – Object

            – Url

            – Type (I use document, but it can be page, place, person, department, team, project, folder, file, document, image, audio, video, or company)

            – Title

            – Image

            – Description

        – Message

        – Private

        – Users (this is a list of the Actor type above)

To actually create a new OGO then I just create an instance of my OGO .NET class that I described above and start setting properties.

YammerGraphObject go = new YammerGraphObject();

go.Activity.Actor = new YammerActor("Steve Peschka", "speschka@yammo.onmicrosoft.com");
go.Activity.Message = "This is for the new vacation policy document.";  
go.Activity.Action = "create";

So I've created the object I'm going to send to Yammer and plugged in the Actor (me!) who will be the contact for it.  Now I'm going to add a couple of other people that I want to notify about the new OGO:

go.Activity.Users.Add(new YammerActor("Anne Wallace", "annew@yammo.onmicrosoft.com"));
go.Activity.Users.Add(new YammerActor("Garth Fort", "garthf@yammo.onmicrosoft.com"));

The next thing I'm going to do is really create the "meat" of the OGO – the content – and then associate it with my OGO:

YammerGraphObjectInstance jo = new YammerGraphObjectInstance();

jo.Url = "https://www.foo.com/vacation.docx";  
jo.Title = "Vacation Policy";  
jo.Description = "This document details our corporate vacation policy.";
jo.Image = "http://www.travelofix.com/wp-content/uploads/2012/03/vacation.jpg";
jo.Type = "document";

go.Activity.Object = jo;

Now the rest of it is going to be very similar to what I showed in my previous posts.  To create the OGO, I need to do a POST to the Yammer REST endpoint.  That means I need to create some forms data to send to the endpoint out of my OGO.  Fortunately, in my class I override the ToString() method so you can just call that to create your forms data then post it up to Yammer.  I also get to reuse the same MakePostRequest method that I created in my original .NET classes for working with Yammer…like this:

string postData = go.ToString();
response = MakePostRequest(postData, graphPostUrl, accessToken, "application/json");

The Url that I'm posting to – "graphPostUrl" – is covered in the Yammer Open Graph documentation, which can be found at http://developer.yammer.com/opengraph/.  For OGO that endpoint is https://www.yammer.com/api/v1/activity.json. 


With that, you have it – you've just created a new Yammer Open Graph item.  In Part 2 I'll explain how to read and create new postings to the newsfeed for the OGO.

See Part 2 Here:  http://blogs.technet.com/b/speschka/archive/2014/05/29/using-yammer-open-graph-in-net-part-2.aspx

YammerGraphObject.cs.txt

Comments (13)

  1. alexandrad9x says:

    Tao http://dichvuketoanlongbien.com/
    Rủa
    http://dichvuketoanlongbien.com/a2-96-dich-vu-ke-toan-tron-goi.html
    Thằng http://dichvuketoanlongbien.com/a2-98-dich-vu-ke-toan-thue.html
    Cờ
    http://dichvuketoanlongbien.com/a2-103-dich-vu-bao-cao-tai-chinh.html
    http://dichvuketoanlongbien.com/a2-97-dich-vu-quyet-toan-thue.html
    Nào
    http://dichvuketoanlongbien.com/a2-114-dich-vu-ke-toan-tai-29-quan-huyen.html
    Soi
    http://dichvuketoanlongbien.com/i780-dich-vu-ke-toan-thue-tron-goi-tai-bac-ninh.html
    Tài
    http://dichvuketoanlongbien.com/i779-dich-vu-ke-toan-thue-tron-goi-tai-bac-giang.html
    Khoản
    http://dichvuketoanlongbien.com/i778-dich-vu-ke-toan-thue-tron-goi-tai-phu-tho.html

    http://dichvuketoanlongbien.com/i781-dich-vu-ke-toan-thue-tron-goi-tai-hung-yen.html
    Link
    http://dichvuketoanlongbien.com/i782-dich-vu-ke-toan-thue-tron-goi-tai-vinh-phuc.html
    Của
    http://dichvuketoanlongbien.com/i783-dich-vu-ke-toan-thue-tron-goi-tai-hai-phong.html
    Tao. http://www.trungtamketoan.com.vn/
    Chúng
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-ha-noi.html
    Mày
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-tp-hcm.html
    Đủ
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-quang-ninh.html
    Trình
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-duong.html
    Thì
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-giang.html
    Tự
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-ninh.html
    Đi
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-phong.html

    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-nam-dinh.html
    Làm.
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thai-binh.html
    Việc
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thanh-hoa.html

    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-vinh-phuc.html
    Phải
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hung-yen.html
    Rẻ
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-phu-tho.html
    Rách
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-binh-duong.html
    Như http://www.tosvn.com
    Thế. http://iketoan247.blogspot.com
    Loại http://tailieuveketoan.blogspot.com
    Chó http://mauhinhnendep.blogspot.com
    Má. http://www.tosvn.com/search/label/Hack%20CF
    Tao http://www.tosvn.com/search/label/Hack%20AvatarStar
    Rủa http://www.tosvn.com/search/label/Hack%20Warcraft-Dota2
    Những http://hocketoan360.com/category/tai-lieu-ke-toan/
    Thằng http://iketoan247.blogspot.com/search/label/thong-tin-kinh-te
    Soi http://iketoan247.blogspot.com/search/label/tin-bai-ve-thue
    Tao http://hoclamketoan.edu.vn/
    Sẽ http://hoclamketoan.edu.vn/category/khoa-hoc-ke-toan
    Tan http://hoclamketoan.edu.vn/category/dich-vu-ke-toan
    Cửa http://hoclamketoan.edu.vn/category/hoc-lam-ke-toan
    Nát http://hoclamketoan.edu.vn/category/tai-lieu-ke-toan
    Nhà http://hocketoan360.com/
    Haha http://hocketoan360.com/category/khoa-hoc-ke-toan/
    http://hocketoan360.com/category/dich-vu-ke-toan/

  2. Thanks Adam for that really excellent tip! One thing wrt to the undocumented endpoint, I do use that for retrieving an item when I know the object ID, I think the question has been if you don’t know the object ID but you know the associated Url, can you
    find the object ID in Yammer? In my experience I have not been able to do that, unless there is at least one post associated with that OGO. If you know of another way to do so though, please chime in!! 🙂

  3. Adam Toth says:

    Great stuff Steve.

    The endpoint you are posting to is the documented endpoint for creating activity stream items (the items in the Recent Activity box on the upper right of the Yammer home tab). When posting to this endpoint, you create both an activity, and the OGO (if it doesn’t
    exist yet).

    If you don’t want to create the activity, you can use the undocumented endpoint
    https://api.yammer.com/api/v1/open_graph_objects/ with a POST request to only create the OGO. You pass a url parameter, and a props JSON string parameter (e.g. props={"title":"some title"})

    I mention this because you can also use this endpoint to retrieve OGOs by URL only (use a GET request), delete OGOs, or get by OGO ID (/api/v1/open_graph_objects/[:ogo_id]).

    It’s a good endpoint to use for working with the OGOs, without having to create messages or activities as well.

  4. Anonymous says:

    it is time for a new collection of my weekly nuggets. Time was flying and I was very busy with my two

  5. Anonymous says:

    This is going to be a multi-part series to dissect and tear apart an application I tweeted about using

  6. Anonymous says:

    In Part 1 of this series, I introduced you to the CloudTopia app. In Part 2 we’re going to look

  7. ASF says:

    http://www.shopbestgoods.com/
    http://www.nike-jordanshoes.com/
    http://www.beatsbydreoutlet.net/
    http://www.michaelkorsus.com/
    http://www.polo-tshirts.com/
    http://www.northsclearance.com/
    http://www.ralph-laurensale.com/
    http://www.gucci-shoesuk2014.com/
    http://www.michael-korsusa.com/
    http://www.polo-outlets.com/
    http://www.ralphslauren.co.uk/
    http://www.marcjacobsonsale.com/
    http://www.mcmworldwides.com/
    http://www.salongchamppairs.com/
    http://www.canada-gooser.com/
    http://www.burberryoutlet2014.com/
    http://www.michaelkors.so/
    http://www.hermes-outletonline.com/
    http://www.oakley-sunglassoutlet.com/
    http://www.north-faceoutlets.net/
    http://www.moncler-clearance.com/
    http://www.woolrich-clearance.com/
    http://www.barbour-jacketsoutlet.com/
    http://www.moncler-jacketsoutletonline.com/
    http://www.monsterbeatsbydres.net/
    http://www.louis-vuittonblackfriday.com/
    http://www.lv-guccishoesfactory.com/
    http://www.mcmoutlet-jp.com/
    http://www.cheapdiscountoutlet.com/
    http://coachoutlet.iwopop.com/
    http://www.coachsfactoryoutlet.com/
    http://www.coach-blackfriday2014.com/
    http://www.coach-storeoutletonline.com/
    http://www.coach-factorysoutletonline.com/
    http://www.coachccoachoutlet.com/
    http://www.coach-factories.net/
    http://www.coach-pursesoutletonline.com/
    http://www.llouisvuitton-factory.net/
    http://www.coach-outletsusa.com/
    http://www.mksfactoryoutlet.com/
    http://www.zxcoachoutlet.com/
    http://www.mischristmas.com/
    http://www.misblackfriday.com/
    http://www.bestcustomsonline.com/
    http://www.newoutletonlinemall.com/
    http://www.clickmichaelkors.com/
    http://www.cmichaelkorsoutlet.com/
    http://www.ralphlaurenepolo.com/
    http://michaelkorsoutlet.mischristmas.com/
    http://mcmbackpack.mischristmas.com/
    http://monsterbeats.mischristmas.com/
    http://northfaceoutlet.mischristmas.com/
    http://mk.misblackfriday.com/
    http://coachoutlet.misblackfriday.com/
    http://coachfactory.misblackfriday.com/
    http://uggaustralia.misblackfriday.com/
    http://coachpurses.misblackfriday.com/
    http://coachusa.misblackfriday.com/
    http://coach.misblackfriday.com/
    http://michaelkorss.misblackfriday.com/
    http://michaelkors.misblackfriday.com/
    http://airmax.misblackfriday.com/
    http://michael-kors.misblackfriday.com/

    http://t.co/1PJuejI1ys
    http://t.co/FYm2MxWwLM
    https://twitter.com/CoachOutlet2014
    https://www.facebook.com/pages/Coach-Factory-Outlet-Online-Store-Michael-Kors-Outlet-Online-Sale-75-Off/712060898859091
    https://www.facebook.com/pages/Ralph-Lauren-Polo-Outlet-Online-Sale/1404100279810690

  8. Pradeepo says:

    Hi,

    I am trying to post to Yammer (using open Graph) from .Net Application an object type=DEPARTMENT or Person to Yammer using Open Graph activity

    yammergraphobjectinst.URL = "Some URL";
    yammergraphobjectinst.Title = "Contoso’s Stress Management";
    yammergraphobjectinst.Description = "Contoso’s Life is stressful – both at work and in your personal life. Sometimes you just need a little help to sort it all out.";
    yammergraphobjectinst.Image = path";
    yammergraphobjectinst.Type = "department";

    Can anybody tell me how do I form the object, specially I want to know value for properties like URL, Title, Image ?

    How do I assign the right values for different properties like URL, Image, Title ) differently for each object type like Person, Department etc

  9. m88 says:

    Michael Owen has time to play M88 :
    http://www.m88no.com/Main/Home.aspx?affiliateId=99156
    failed at Old Trafford. However, the former England football prodigy has created numerous imprints made ​​many people to mention his name. One that is mixed in injury time scorer, helping Manchester United win before choking rival 4-3.

    3. Wayne Rooney wheel hit the net Crystal-class M88 Joe Hart (12/02/2011)

    Rooney is regarded as the king of the M88 Manchester derby match recording 11 goals / 22 games. But definitely not a goal to bring many emotions NHM R10 each phase as "anti-reverse cycling" Joe Hart into the net, 3 years ago.

    Goal for this lifetime is Premier League BTC voted "most beautiful goal Premier League history."

  10. Derek Gusoff says:

    Hi Steve, this is excellent stuff, there is very little quality documentation of Yammer development outside your blog and the Patterns and Practices samples. I was initially getting a 400 response running your sample but got it to work by converting the
    json properties in the request to lower case. This was easy enough to do in the overridden ToString() method you provided. Again, thanks!

  11. m88 says:

    m88 : http://m88en.com
    M88.com offer online sports games Asia, Sports Betting Asia, Sports Betting Sites Asia.

    m88asia : http://m88en.net
    Link to M88BET phone: m88en.com. – Register and Open Betting Account and Membership M88BET.

    m88bet : http://www.linkm88vip.com
    MANSION88 the house is one of the largest and most prestigious. Appeared quite early in the Asian market, the so-MANSION88 currently attracts more players.

    link m88 : http://m88wiki.com
    Home the M88 is the official sponsor of the football club in the Premier League
    Wish you happy with the new M88
    m88 casino online : http://m88free.com

    Modern Thai restaurant combines outstanding traditional cuisine and a subtle modern decor with a warm welcoming ambience. Thai Restaurants in Brisbane :
    http://www.watersidethainoodles.com.au/ , traveller reviews of Brisbane Thai restaurants and search by price, location, and more..