मैं एक डेमो एप्लिकेशन के लिए फ़्लिकर एपीआई को प्रमाणित करने का प्रयास कर रहा हूं जिसे मैं अपने लिए बनाना चाहता हूं। फिर मैं इस ऐप को नई सुविधाओं के साथ बढ़ा दूंगा जो मैं फ्लिक एपीआई के बारे में सीखूंगा।फ़्लिकर एपीआई (कंसोल में सिमुलेशन) पर हस्ताक्षर अनुरोधों के लिए अमान्य हस्ताक्षर
तो यह सिर्फ कुछ है जिसे मैं खेलना चाहता हूं। लेकिन अब मुझे अनुरोध टोकन प्राप्त करने में कुछ परेशानी है।
मैं यहाँ फ़्लिकर प्रमाणीकरण दस्तावेज़ अनुसरण कर रहा हूं: Flickr Authentication
और मैं यह भी पाया इस Mathlabscript: Flickr API with OAuth-based user authentication
तो इन स्रोतों के आधार पर मेरे पास है अब निम्नलिखित सांत्वना आवेदन:
class Program
{
private static string Secret = "2b2b2b2b2b2b2b2b2b";
private static string ConsumerKey = "1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a";
static void Main(string[] args)
{
Random rand = new Random();
string nonce = rand.Next(9999999).ToString();
string timestamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
Console.WriteLine("Nonce: " + nonce);
Console.WriteLine("TimeStamp: " + timestamp);
Console.WriteLine("ConsumerKey: " + ConsumerKey);
Console.WriteLine("AppSecret: " + Secret);
//request url
StringBuilder b = new StringBuilder();
b.Append("http://www.flickr.com/services/oauth/request_token");
b.Append("?");
b.Append("oauth_nonce=");
b.Append(nonce);
b.Append("&oauth_timestamp=");
b.Append(timestamp);
b.Append("&oauth_consumer_key=");
b.Append(ConsumerKey);
b.Append("&oauth_callback=oob");
b.Append("&oauth_signature_method=HMAC-SHA1");
string requesturl = b.ToString();
Console.WriteLine("RequestUrl: " + requesturl);
//base url
string basestring;
StringBuilder bs = new StringBuilder();
bs.Append("GET&");
bs.Append(UrlHelper.Encode("http://www.flickr.com/services/oauth/request_token")+"&");
basestring = bs.ToString();
StringBuilder p = new StringBuilder();
p.Append("oauth_callback=oob");
p.Append("&oauth_consumer_key=");
p.Append(ConsumerKey);
p.Append("oauth_nonce=");
p.Append(nonce);
p.Append("&oauth_signature_method=HMAC-SHA1");
p.Append("&oauth_timestamp=");
p.Append(timestamp);
string paramers = UrlHelper.Encode(p.ToString());
basestring += paramers;
Console.WriteLine("Basestring: " + basestring);
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string key = Secret + "&";
Console.WriteLine("Key: " + key);
byte[] keyByte = encoding.GetBytes(key);
//--create message to encrypt
byte[] messageBytes = encoding.GetBytes(basestring);
//--encrypt message using hmac-sha1 with the provided key
HMACSHA1 hmacsha1 = new HMACSHA1(keyByte);
byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);
//--signature
string signature = ByteToString(hashmessage);
Console.WriteLine("Signature: " + signature);
Console.WriteLine("Final Request: " + requesturl + "&oauth_signature=" + signature);
Console.ReadKey(true);
}
public static string ByteToString(byte[] buff)
{
string sbinary = "";
for (int i = 0; i < buff.Length; i++)
{
sbinary += buff[i].ToString("X2"); // hex format
}
return (sbinary);
}
}
जब मैं यूआरएल को ब्राउज़ करता हूं, यह एप्लिकेशन मुझे देता है, मुझे निम्न प्रतिक्रिया मिलती है:
oauth_problem=signature_invalid&debug_sbs=GET&http%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Fwww.google.be%26oauth_consumer_key%3D1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a%26oauth_nonce%3D27504343%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1329469580
ऐसा लगता है कि अनुरोध के लिए मेरा हस्ताक्षर अमान्य है।
मुझे आशा है कि कोई मुझे इन अनुरोधों के लिए सही हस्ताक्षर प्राप्त करने में मदद कर सकता है।
मुझे पता है कि एक फ़्लिकनेट लाइब्रेरी है जो पहले से ही अधिकांश डेवलपर्स के लिए कड़ी मेहनत कर चुकी है लेकिन मुझे लगता है कि यह काम करने के लिए भी उपयोगी हो सकता है। मैंने फ़्लिकरनेट के स्रोत कोड में देखा लेकिन इस कोड को पूरा करने के लिए अंतिम शांति नहीं मिली।
मुझे बताएं कि क्या आप मेरी मदद कर सकते हैं। यह बहुत अच्छा होगा!
धन्यवाद!
अपने आप को ध्यान दें: ओथ प्रमाणीकरण के बारे में अधिक जानकारी यहां मिल सकती है: http://hueniverse.com/oauth/guide/authentication/ जितनी जल्दी हो सके मैं इसे देख लूंगा :) – ThdK