API的报告生成

瓦考

新成员
已加入
2020年10月16日
留言内容
3
编程经验
Beginner
您好社区,我想从api获取一些详细信息。我已经调用了api,并收到了json格式的响应。但是,所有详细信息未正确显示。我需要这方面的帮助。结果会生成重复的值,并且所有结果都不会得到。我所做的一切都是为了数不清。的可见与否。评论数
C#:
String searchResults = null;

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

List<Threads> listPosts = new List<Threads>();
Threads outerLoopThread = new 线程数();
string url = "//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 留言内容();

    outerLoopThread.messageCount = jObject.SelectToken("threads[0].messages").Count();
    outerLoopThread.strPostURL = "//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"))
        {
            线程数 thread = new 线程数();

            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 = "//www.yammer.com/mdlz.com/threads/" + jObject.SelectToken("threads["+i+"].messages[0]").SelectToken("thread_id");

            listPosts.Add(thread);
        }
 
由主持人最后编辑:

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,501
地点
悉尼,澳大利亚
编程经验
10+
也许为我们提供了关于您期望获得和实际获得的收益的清晰描述和/或示例。尽管有时是可能的,但我们不必从不执行此操作的代码中找出您要执行的操作。
 

瓦考

新成员
已加入
2020年10月16日
留言内容
3
编程经验
Beginner
也许为我们提供了关于您期望获得和实际获得的收益的清晰描述和/或示例。尽管有时是可能的,但我们不必从不执行此操作的代码中找出您要执行的操作。
我的错。我正在尝试以以下形式获取报告

帖子标题发布链接发布日期帖子中用户喜欢的数量用户对评论的喜欢总数用户对帖子的评论数股数看到的数量

但是我没有正确地得到它并得到重复的记录。我还需要获取所有记录,并在每页中获取20条记录。
 

跳伞

工作人员
已加入
2019年4月6日
留言内容
2,500
地点
弗吉尼亚州切萨皮克
编程经验
10+
可以假定,当您在第8行组装查询字符串参数时,您会阅读Yammer API文档,并且Yammer API文档会告诉您期望返回哪种数据。您能否提供该文档的链接,并用自己的语言解释您认为您在处理结果时所采取的措施与该文档相符?

还附上一份"parse.json"可以帮助我们可视化数据。
 

瓦考

新成员
已加入
2020年10月16日
留言内容
3
编程经验
Beginner
不幸的是,正式只有v1 API可用,但它没有提供完整的数据。在网络标签中,内部调用了V2。
 

附件

  • parse.json.txt
    166.4 KB · 观看次数: 3

跳伞

工作人员
已加入
2019年4月6日
留言内容
2,500
地点
弗吉尼亚州切萨皮克
编程经验
10+
如果尚未记录,则可能尚未开放供公众使用,因此您不应该使用它。
 
最佳 底部