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

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

问题描述



例如:某些链接被分享到Facebook,Twitter的次数有多少, LinkedIn计算某些内容的受欢迎程度。



如何获取共享数我的特定api?还有其他选择吗?
是否有一些api?

解决方案

我发现答案... !!!!!!!



数据URL
这里可以找到数据

  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 [见下面的JSON-RPC]

注意由于我使用动态,所以需要.NET 4.0。另外,我是
使用正式折旧的JavaScriptSerializer类,
,但可能实际上不会被删除。您还可以轻松地使用
Regex来获取这些简单的值。
*

  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];

返回计数;
}

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];

返回计数;
}

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 : @观察者 , 的groupId : @自 } jsonrpc : 2.0 键 : p , apiVersion :v1}];

System.Net.HttpWebRequest request =(System.Net.HttpWebRequest)System.Net.WebRequest.Create(googleApiUrl);
请求。 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 .GetResponse流();
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()替换(.0,) );

返回计数;}


Is there any way to get number of users share some link on Facebook,Twitter,LinkedIn

example: how many times some link was shared to Facebook,Twitter,LinkedIn to calculate popularity of some content.

how to get share count my particular api ? is there any other option ? Are there some api ?

解决方案

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]

Note: Since I’m using "dynamic," this requires .NET 4.0. Also, I’m using the JavaScriptSerializer class which is officially depreciated, but will probably not actually be removed. You could also easily use Regex to get these simple values.*

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天全站免登陆