Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am trying so many ways but i am not getting any details..

C#
var oauth_token = "DojseHuV3PmX6AiDzoK5PCN3OO81FkFdAKwm5b4Gv9WmJMFjZi";
var oauth_token_secret = "bp2r2NU7m4I6CJ6mAeVcZeGSfMDaQZhshnSskk4LarPCaDG2yw";
var oauth_consumer_key = "NwmM3pcR8GeRqdjZ50JRNO7UckxmYMUPH32SAsLsErDfg8kAQ6";
var oauth_consumer_secret = "POlW1lez9HsmLwIW3Pt9SBdvgASxXQuDsT92FeKUJGicDqmMQ8";

var oauth_version = "1.0";
var oauth_signature_method = "HMAC-SHA1";
var oauth_nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(
DateTime.Now.Ticks.ToString()));
var timeSpan = DateTime.UtcNow
- new DateTime(1970, 1, 1, 0, 0, 0, 0,
DateTimeKind.Utc);
var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();
var resource_url = "https://api.tumblr.com/v2/blog/50watts.tumblr.com/followers";
var status = "Updating status via REST API if this works";


var baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
"&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&status={6}";

var baseString = string.Format(baseFormat,
oauth_consumer_key,
oauth_nonce,
oauth_signature_method,
oauth_timestamp,
oauth_token,
oauth_version,
Uri.EscapeDataString(status)
);

baseString = string.Concat("POST&", Uri.EscapeDataString(resource_url),
"&", Uri.EscapeDataString(baseString));



var compositeKey = string.Concat(Uri.EscapeDataString(oauth_consumer_secret),
"&", Uri.EscapeDataString(oauth_token_secret));

string oauth_signature;
using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
{
oauth_signature = Convert.ToBase64String(
hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
}

var headerFormat = "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " +
"oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", " +
"oauth_token=\"{4}\", oauth_signature=\"{5}\", " +
"oauth_version=\"{6}\"";



var authHeader = string.Format(headerFormat,
Uri.EscapeDataString(oauth_nonce),
Uri.EscapeDataString(oauth_signature_method),
Uri.EscapeDataString(oauth_timestamp),
Uri.EscapeDataString(oauth_consumer_key),
Uri.EscapeDataString(oauth_token),
Uri.EscapeDataString(oauth_signature),
Uri.EscapeDataString(oauth_version)
);

var postBody = "status=" + Uri.EscapeDataString(status);

ServicePointManager.Expect100Continue = false;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
request.Headers.Add("Authorization", authHeader);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (Stream stream = request.GetRequestStream())
{
byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
}
WebResponse response = request.GetResponse();
Posted
Updated 2-Apr-15 9:43am
v3
Comments
Maciej Los 1-Apr-15 16:04pm
   
Not clear!
Member 10614730 2-Apr-15 5:08am
   
i am trying to oauth authentication process and using node.js but i am not getting any details..
Member 10614730 2-Apr-15 5:09am
   
var oauth_token = "DojseHuV3PmX6AiDzoK5PCN3OO81FkFdAKwm5b4Gv9WmJMFjZi";
var oauth_token_secret = "bp2r2NU7m4I6CJ6mAeVcZeGSfMDaQZhshnSskk4LarPCaDG2yw";
var oauth_consumer_key = "NwmM3pcR8GeRqdjZ50JRNO7UckxmYMUPH32SAsLsErDfg8kAQ6";
var oauth_consumer_secret = "POlW1lez9HsmLwIW3Pt9SBdvgASxXQuDsT92FeKUJGicDqmMQ8";

var oauth_version = "1.0";
var oauth_signature_method = "HMAC-SHA1";
var oauth_nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(
DateTime.Now.Ticks.ToString()));
var timeSpan = DateTime.UtcNow
- new DateTime(1970, 1, 1, 0, 0, 0, 0,
DateTimeKind.Utc);
var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();
var resource_url = "https://api.tumblr.com/v2/blog/50watts.tumblr.com/followers";
var status = "Updating status via REST API if this works";


var baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
"&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&status={6}";

var baseString = string.Format(baseFormat,
oauth_consumer_key,
oauth_nonce,
oauth_signature_method,
oauth_timestamp,
oauth_token,
oauth_version,
Uri.EscapeDataString(status)
);

baseString = string.Concat("POST&", Uri.EscapeDataString(resource_url),
"&", Uri.EscapeDataString(baseString));



var compositeKey = string.Concat(Uri.EscapeDataString(oauth_consumer_secret),
"&", Uri.EscapeDataString(oauth_token_secret));

string oauth_signature;
using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
{
oauth_signature = Convert.ToBase64String(
hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
}

var headerFormat = "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " +
"oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", " +
"oauth_token=\"{4}\", oauth_signature=\"{5}\", " +
"oauth_version=\"{6}\"";



var authHeader = string.Format(headerFormat,
Uri.EscapeDataString(oauth_nonce),
Uri.EscapeDataString(oauth_signature_method),
Uri.EscapeDataString(oauth_timestamp),
Uri.EscapeDataString(oauth_consumer_key),
Uri.EscapeDataString(oauth_token),
Uri.EscapeDataString(oauth_signature),
Uri.EscapeDataString(oauth_version)
);

var postBody = "status=" + Uri.EscapeDataString(status);

ServicePointManager.Expect100Continue = false;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
request.Headers.Add("Authorization", authHeader);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (Stream stream = request.GetRequestStream())
{
byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
}
WebResponse response = request.GetResponse();
Afzaal Ahmad Zeeshan 2-Apr-15 6:59am
   
Do they have a C# API? I don't think so. They were having JavaScript, PHP etc APIs only.
Member 10614730 2-Apr-15 13:31pm
   
Suggest me how to do in javaScript
Afzaal Ahmad Zeeshan 2-Apr-15 21:03pm
   
See my answer please.
Maciej Los 2-Apr-15 6:11am
   
Do not post code in comment. Use "Improve question" widget to update question.

1 solution

Please read their API[^], they've got all of the methods, functions stated there.

So, for example your problem. Getting the followers, you can use this URI,

api.tumblr.com/v2/blog/{base-hostname}/followers


To get the followers, please read the API I have suggested to you. They also have a set of languages already defined, if they're not being used you can always use these URI to get results in JSON format. However, JavaScript is added in the list.
   
Comments
Member 10614730 3-Apr-15 5:02am
   
i am already tried that..but it says "oauth Authentication" process. i don't no how to Authentication OAuth process..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900