Facebook、Twitter、LinkedIn 共享链接数 [英] Facebook, Twitter, LinkedIn share link count

查看:33
本文介绍了Facebook、Twitter、LinkedIn 共享链接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让用户在 Facebook、Twitter 和 LinkedIn 上分享链接的数量?

Is there any way to get the number of users to share a link on Facebook, Twitter, and LinkedIn?

示例:某个链接被分享到 Facebook、Twitter 和 LinkedIn 多少次以计算某些内容的受欢迎程度?

Example: How many times some link was shared to Facebook, Twitter, and LinkedIn to calculate the popularity of some content?

如何获取我的特定 API 的份额数?还有其他选择吗?有API吗?

How to get share count my particular API? Is there any other option? Is there some API?

推荐答案

I found Answer ...!!!!!!

I found Answer ...!!!!!!!

数据网址在这里你可以找到数据

Data URLs Here’s where you can find the data

Facebook    http://graph.facebook.com/?ids=YOURURL
Twitter http://urls.api.twitter.com/1/urls/count.json?url=YOURURL
Google  https://clients6.google.com/rpc [see below for JSON-RPC]

注意:由于我使用的是动态",因此需要 .NET 4.0.还有,我使用官方已弃用的 JavaScriptSerializer 类,但实际上可能不会被删除.您也可以轻松使用正则表达式来获取这些简单的值.*

int GetTweets(string url) {

    string jsonString = new System.Net.WebClient().DownloadString("http://urls.api.twitter.com/1/urls/count.json?url=" + url);

    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(jsonString);
    int count = (int)json["count"]; 

    return count;
}

int GetLikes(string url) {

    string jsonString = new System.Net.WebClient().DownloadString("http://graph.facebook.com/?ids=" + url);

    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(jsonString);
    int count = json[url]["shares"];

    return count;
}

int GetPlusOnes(string url) {

    string googleApiUrl = "https://clients6.google.com/rpc"; //?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ";

    string postData = @"[{""method"":""pos.plusones.get"",""id"":""p"",""params"":{""nolog"":true,""id"":""" + url + @""",""source"":""widget"",""userId"":""@viewer"",""groupId"":""@self""},""jsonrpc"":""2.0"",""key"":""p"",""apiVersion"":""v1""}]";

    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(googleApiUrl);
    request.Method = "POST";
    request.ContentType = "application/json-rpc";
    request.ContentLength = postData.Length;

    System.IO.Stream writeStream = request.GetRequestStream();
    UTF8Encoding encoding = new UTF8Encoding();
    byte[] bytes = encoding.GetBytes(postData);
    writeStream.Write(bytes, 0, bytes.Length);
    writeStream.Close();

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    System.IO.Stream responseStream = response.GetResponseStream();
    System.IO.StreamReader readStream = new System.IO.StreamReader(responseStream, Encoding.UTF8);
    string jsonString = readStream.ReadToEnd();

    readStream.Close();
    responseStream.Close();
    response.Close();

    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(jsonString);
    int count = Int32.Parse(json[0]["result"]["metadata"]["globalCounts"]["count"].ToString().Replace(".0", ""));

    return count;}

这篇关于Facebook、Twitter、LinkedIn 共享链接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆