Question Report generation for an api

vaikau

New member
Joined
Oct 16, 2020
Messages
3
Programming Experience
Beginner
Hello Community, I want to get some details from an api. I have called the api and received the response in json format. However, all details are not shown correctly. I need help around this. The result generates values in duplicate and also all results are not getting. All I am doing this for getting count for no. of seen and no. of comments
C#:
String searchResults = null;

// var authToken = "452735-NwERnvL926kGF0ToAxgA";
var authToken = ConfigurationManager.AppSettings["accessToken"];

List<Threads> listPosts = new List<Threads>();
Threads outerLoopThread = new Threads();
string url = "https://www.yammer.com/api/v2/networks/452735/feeds/user/1646760526?include_thread_starter=true&threads_count=20&messages_count=0&older_than=801135469215744&for_feed=user&treatment=true_discovery_feed_sources_v3%3Ainclude_top_sources%2Cdiscovery_feed_promoted_posts%3Atrue%2Cdiscovery_feed_ml_personalized_gbt_v10%3Arankiechoosie&fetch_type=olderThan";

using (var webClient = new WebClient())
{
    webClient.Headers.Add("Authorization", "Bearer " + authToken);
    string HtmlResult = webClient.UploadString(url, "feed(id,network_id,channel_id,last_seen_message_id,has_older_threads,unseen_thread_count,threads(id,network_id,channel_id,group_ids,thread_starter_id,first_reply_id,latest_reply_at,latest_reply_id,read_only,is_reply_disabled,has_attachments,messages_count,share_count,topics,participants,in_private_conversation,messages(id,network_id,group_id,thread_id,sender_id,replied_to_id,shared_message_id,file_ids,page_ids,client_type_id,created_at,language,message_type,message_subtype,sender_type,body,title,in_private_conversation,references,version_num,updated_at,praise(id,network_id,message_id,praised_user_ids,comment,icon),content_state,is_bookmarked,is_liked,like_ids,likes_count,is_edited,is_editable,poll_options(option,answer,count,selected),connector_card,previous_versions(id,network_id,group_id,thread_id,sender_id,replied_to_id,shared_message_id,file_ids,page_ids,client_type_id,created_at,language,message_type,message_subtype,sender_type,body,title,in_private_conversation,references,version_num,updated_at,praise(id,network_id,message_id,praised_user_ids,comment,icon),content_state)),state(last_read_message,is_following,priority_reason,can_mark_best_reply),explanation,unique_views_count,created_at,broadcast_event_id,best_reply_id,best_reply_marked_by_user_id),reference_data(client_applications(id,name,url),networks(id,name),groups(id,network_id,mugshot_id,permalink,name,private,moderated,color),users(id,network_id,mugshot_id,activated_at,permalink,full_name,job_title,state,email,is_following),guides(id,network_id,mugshot_id,permalink,full_name),files(id,network_id,group_id,latest_version_id,created_at,last_uploaded_at,name,original_name,description,content_type,size,width,height,transcoded,in_private_conversation,in_private_group,icon,state,is_following,is_editable,storage_type),opengraphobjects(id,record_id,network_id,url,image,title,description,state,is_following,video_url,provider_name),pages(id,network_id,group_id,latest_version_id,updated_at,title,official,state,is_following),tags(id),topics(id,tag_id,network_id,name,normalized_name),shared_messages(id,network_id,group_id,thread_id,sender_id,replied_to_id,shared_message_id,file_ids,page_ids,client_type_id,created_at,language,message_type,message_subtype,sender_type,body,title,in_private_conversation,references,version_num,updated_at,praise(id,network_id,message_id,praised_user_ids,comment,icon),content_state,is_bookmarked,is_liked,like_ids,likes_count,is_edited,is_editable,poll_options(option,answer,count,selected),connector_card),replied_to_messages(id,network_id,group_id,thread_id,sender_id,replied_to_id,shared_message_id,file_ids,page_ids,client_type_id,created_at,language,message_type,message_subtype,sender_type,body,title,in_private_conversation,references,version_num,updated_at,praise(id,network_id,message_id,praised_user_ids,comment,icon),content_state,is_bookmarked,is_liked,like_ids,likes_count,is_edited,is_editable,poll_options(option,answer,count,selected),connector_card),thread_summaries(id,network_id,group_ids,thread_starter_id,in_private_conversation,messages_count,share_count),broadcasts(id,yammer_group_id,broadcast_id,title),best_reply_messages(id,network_id,group_id,thread_id,sender_id,replied_to_id,shared_message_id,file_ids,page_ids,client_type_id,created_at,language,message_type,message_subtype,sender_type,body,title,in_private_conversation,references,version_num,updated_at,praise(id,network_id,message_id,praised_user_ids,comment,icon),content_state,is_bookmarked,is_liked,like_ids,likes_count,is_edited,is_editable,poll_options(option,answer,count,selected),connector_card,previous_versions(id,network_id,group_id,thread_id,sender_id,replied_to_id,shared_message_id,file_ids,page_ids,client_type_id,created_at,language,message_type,message_subtype,sender_type,body,title,in_private_conversation,references,version_num,updated_at,praise(id,network_id,message_id,praised_user_ids,comment,icon),content_state))),url_templates(thread,thread_web,message,message_web,attachment,attachment_web,attachment_download,attachment_thumbnail,attachment_scaled,attachment_preview,attachment_stream,attachment_edit,file_large_icon,page,page_web,page_preview,user,user_web,user_mugshot,group,group_web,group_mugshot,topic,topic_web,tag))");
    JObject jObject = JObject.Parse(File.ReadAllText("C:\\Desktop\\parse.json"));

    //no. of threads and messages
    Console.WriteLine(jObject.SelectToken("threads").Count());
    Console.WriteLine(jObject.SelectToken("threads[0].messages").Count());

    //no of seen
    Console.WriteLine(jObject.SelectToken("threads[0]").SelectToken("unique_views_count"));

    //post created
    Console.WriteLine(jObject.SelectToken("threads[0]").SelectToken("created_at"));

    //no. of posts
    Console.WriteLine(jObject.SelectToken("threads[0]").SelectToken("messages_count"));

    //post title
    Console.WriteLine(jObject.SelectToken("threads[0].messages[0]").SelectToken("body"));

    //no. of likes count on post   
    Console.WriteLine(jObject.SelectToken("threads[0].messages[0]").SelectToken("likes_count"));

    //no. of shares
    Console.WriteLine(jObject.SelectToken("threads[0]").SelectToken("share_count"));

    //form link to post
    Console.WriteLine(jObject.SelectToken("threads[0].messages[0]").SelectToken("thread_id"));

    outerLoopThread.threadsCount=jObject.SelectToken("threads").Count();
    outerLoopThread.unique_views_count = jObject.SelectToken("threads[0].messages").Count();

    //Messages message = new Messages();

    outerLoopThread.messageCount = jObject.SelectToken("threads[0].messages").Count();
    outerLoopThread.strPostURL = "https://www.yammer.com/abc.com/threads/"+ jObject.SelectToken("threads[0].messages[0]").SelectToken("thread_id");

    for (int i = 0; i <= outerLoopThread.unique_views_count; i++)
    {                   
        foreach (var msgItem in jObject.SelectToken("threads["+i+"].messages"))
        {
            Threads thread = new Threads();

            Console.WriteLine(jObject.SelectToken("threads["+i+"].messages").Count());                       

            int msgCount = jObject.SelectToken("threads["+i+"].messages").Count();

            thread.postTitle=jObject.SelectToken("threads["+i+"].messages["+(msgCount-1)+"]").SelectToken("title").ToString();

            //no. of likes count on post   
            thread.likes_count=Convert.ToInt32(jObject.SelectToken("threads["+i+"].messages["+(msgCount-1)+"]").SelectToken("likes_count"));

            //no. of shares
            thread.share_count=Convert.ToInt32(jObject.SelectToken("threads["+i+"]").SelectToken("share_count"));

            //form link to post

            //thread.thread_id=Convert.ToInt64(jObject.SelectToken("threads["+i+"].messages[" + (msgCount - 1) + "]").SelectToken("thread_id"));
            thread.thread_id =Convert.ToString(jObject.SelectToken("threads[" + i + "].messages[0]").SelectToken("thread_id"));

            //post created
            // Console.WriteLine(DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(jObject.SelectToken("threads[0]").SelectToken("created_at").ToString())).DateTime.ToString("dd-MMM-yyyy hh:mm:ss"));

            thread.created_at=Convert.ToDateTime(DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(jObject.SelectToken("threads[0]").SelectToken("created_at").ToString())).DateTime.ToString("dd-MMM-yyyy hh:mm:ss"));

            //no of comments
            thread.commentsCount=(msgCount-1);

            //no of seen
            //jObject.SelectToken("threads[0].messages").Count()
            //jObject.SelectToken("threads[0]").SelectToken("unique_views_count")

            thread.unique_views_count=Convert.ToInt32(jObject.SelectToken("threads["+i+"]").SelectToken("unique_views_count"));

            //no. of shares
            thread.share_count=(jObject.SelectToken("threads["+i+"]").SelectToken("share_count")).Count();

            thread.strPostURL = "https://www.yammer.com/mdlz.com/threads/" + jObject.SelectToken("threads["+i+"].messages[0]").SelectToken("thread_id");

            listPosts.Add(thread);
        }
 
Last edited by a moderator:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,217
Location
Sydney, Australia
Programming Experience
10+
Perhaps provides us with a clear description and/or example of what you expect to get and what you actually get. While sometimes it's possible, we shouldn't have to work out what you are trying to do from code that doesn't do it.
 

vaikau

New member
Joined
Oct 16, 2020
Messages
3
Programming Experience
Beginner
Perhaps provides us with a clear description and/or example of what you expect to get and what you actually get. While sometimes it's possible, we shouldn't have to work out what you are trying to do from code that doesn't do it.
My bad. I am trying to get the report in the form

Post TitlePost LinkPost DateNo. of User Likes on PostTotal No. of User likes on CommentsNo. of User Comments on PostNo. of ShareNo. of Seen

However i am not getting it correctly and get duplicate records. I also need to get all records and get 20 in each page.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,959
Location
Chesapeake, VA
Programming Experience
10+
One would presume that when you assembled your query string parameters on line 8 that you read the Yammer API documentation, and that the Yammer API documentation tells you what kind of data to expect back. Can you provide a link to that documentation, and explain in your own words how you believe what you are doing to process the results matches with the documentation?

Also attaching a copy of that "parse.json" would help us visualize the data.
 

vaikau

New member
Joined
Oct 16, 2020
Messages
3
Programming Experience
Beginner
unfortunately, officially only v1 api is available but it does not give full data. From the networks tab, V2 is internally being called.
 

Attachments

  • parse.json.txt
    166.4 KB · Views: 1

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,959
Location
Chesapeake, VA
Programming Experience
10+
If it's not yet documented, then probably it is not yet open for public use, and you shouldn't be using it yet.
 
Top Bottom