asp.net中的任何藤蔓api?

时间:2014-02-27 08:29:33

标签: asp.net curl vine

我正在努力转换asp.net中的藤api代码,我从这里发现,任何人都有任何想法?

如果有人知道如何将此卷曲转换为asp.net

,那真的很感激
class Vine {

private static $base_url = "https://api.vineapp.com";
private static $referer = "api.vineapp.com";
private static $vine_session = null;
private static $vine_id = null;

public static function login($username, $password) {
$success = false;
$url = self::$base_url . "/users/authenticate";
$curl = new Curl;
$response = json_decode($curl->post($url, array('username'=>$username, 'password'=>$password)));
if(isset($response->success) and $response->success) {
self::$vine_session = $response->data->key;
self::$vine_id = $response->data->key;
$success = true;
}
return $success;    
}

public static function get_tag($tag) {
$encoded_tag = urlencode($tag);
$url = self::$base_url . "/timelines/tags/$encoded_tag";
$payload = null;
$curl = new Curl;
if(self::$vine_session) {
$curl->headers['vine-session-id'] = self::$vine_session;
}
$response = json_decode($curl->get($url));
if(isset($response->success) and $response->success) {
$payload = $response->data->records;
}
return $payload;
}

}

1 个答案:

答案 0 :(得分:0)

最后,我成功地使用C#从葡萄藤中获取饲料。下面的代码为 做这件事。

            string data = "username=yourusername&password=password"; //replace <value>
            byte[] dataStream = Encoding.UTF8.GetBytes(data);
            string urlPath = "https://api.vineapp.com/users/authenticate";
            string request = urlPath;
            WebRequest webRequest = WebRequest.Create(request);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ContentLength = dataStream.Length;
            Stream newStream = webRequest.GetRequestStream();
            // Send the data.
            newStream.Write(dataStream, 0, dataStream.Length);
            newStream.Close();
            WebResponse webResponse = webRequest.GetResponse();
            Stream responseStream = webResponse.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            string responseFromServer = reader.ReadToEnd();
            JObject js1 = JObject.Parse(responseFromServer);
            string key=js1["data"]["key"].ToString();

            //GetVineUsers();
            string URL = "https://api.vineapp.com/users/search/"+txtName.Text;

            var webClient = new WebClient();
            webClient.Headers.Add("user-agent", "com.vine.iphone/1.0.3 (unknown, iPhone OS 6.0.1, iPhone, Scale/2.000000)");
            webClient.Headers.Add("vine-session-id", key);
            webClient.Headers.Add("accept-language", "en, sv, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8");
            var json = webClient.DownloadString(URL);
            JObject js = JObject.Parse(json);
            for (int i = 0; i < 19; i++)
            {
                FbUser cls = new FbUser();
                cls.Id = js["data"]["records"][i]["userId"].ToString();
                cls.Name = js["data"]["records"][i]["username"].ToString();
                cls.MediaName = "Vine";
                listFbUsers.Add(cls); 
            }