示例#1
0
文件: VK.cs 项目: JoyHood/VKparser
        public static string AddFriend(int userId, string accessToken)
        {
            var api = new VKAPI(accessToken);
            var queryIsMyfriend = new NameValueCollection();
            queryIsMyfriend["user_ids"] = userId.ToString();
            queryIsMyfriend["need_sign"] = "1";
            var isMyfriend = api.ExecuteCommand(Constants.IS_MY_FRIEND, queryIsMyfriend);
            var data = JsonConvert.DeserializeObject<RootJson>(isMyfriend);
            if (data.response != null)
            {
                // check: this user isn't my friend yet
                var response = data.response.FirstOrDefault();
                if (response != null && response.friend_status == "0")
                {
                    var queryString = new NameValueCollection();
                    queryString["user_id"] = userId.ToString();
                    queryString["text"] = Constants.ADDFRIEND_TEXT;

                    var addToFriends = api.ExecuteCommand(Constants.ADD_TO_MYFRIENDS, queryString);
                    return addToFriends;
                }
            }
            return "-1";
        }
示例#2
0
 private IEnumerable<int> GetFriends(string accessToken)
 {
     var friends = new List<int>();
     var api = new VKAPI(accessToken);
     string jsonString = api.ExecuteCommand(Constants.GET_FRIENDS, null);
     var json = JObject.Parse(jsonString);
     friends.AddRange(((JArray)json["response"]).Select(friend => (int)friend));
     return friends;
 }
示例#3
0
 private bool IsMember(int userId, string groupId, string accessToken)
 {
     var api = new VKAPI(accessToken);
     var queryString = new NameValueCollection();
     queryString["group_id"] = groupId;
     queryString["user_id"] = userId.ToString();
     string jsonString = api.ExecuteCommand(Constants.IS_MEMBER, queryString);
     var json = JObject.Parse(jsonString);
     return (bool)json["response"];
 }
示例#4
0
 private void Invite(int userId, string groupId, string accessToken)
 {
     var api = new VKAPI(accessToken);
     var queryString = new NameValueCollection();
     queryString["group_id"] = groupId;
     queryString["user_id"] = userId.ToString();
     api.ExecuteCommand(Constants.INVITE_FRIEND, queryString);
 }
示例#5
0
 private void GetInvitedUsers(string groupId, string accessToken)
 {
     var take = 1000;
     var offset = 0;
     var users = new List<int>();
     var api = new VKAPI(accessToken);
     var queryString = new NameValueCollection();
     queryString["group_id"] = groupId;
     queryString["count"] = "1";
     string jsonString = api.ExecuteCommand(Constants.GET_INVITED_USERS, queryString);
     var json = JObject.Parse(jsonString);
     count = (int)json["response"][0];
     while (offset <= count)
     {
         Thread.Sleep(500);
         queryString["count"] = take.ToString();
         queryString["offset"] = offset.ToString();
         jsonString = api.ExecuteCommand(Constants.GET_INVITED_USERS, queryString);
         json = JObject.Parse(jsonString);
         for (int i = 1; i <= count; i++)
         {
             users.Add((int)json["response"][i]["uid"]);
         }
         offset = offset + take + 1;
     }
     _invitedUsers = users;
 }
示例#6
0
 private List<int> GetGroupMembers(string groupId, string accessToken)
 {
     var take = 1000;
     var offset = 0;
     var items = new List<int>();
     var api = new VKAPI(accessToken);
     var queryString = new NameValueCollection();
     queryString["group_id"] = groupId;
     queryString["count"] = "1";
     string jsonString = api.ExecuteCommand(Constants.GET_MEMBERS, queryString);
     var json = JObject.Parse(jsonString);
     count = (int)json["response"]["count"];
     while (offset <= count)
     {
         Thread.Sleep(500);
         queryString["count"] = take.ToString();
         queryString["offset"] = offset.ToString();
         jsonString = api.ExecuteCommand(Constants.GET_MEMBERS, queryString);
         json = JObject.Parse(jsonString);
         items.AddRange(((JArray)json["response"]["users"]).Select(item => (int)item));
         offset = offset + take+1;
     }
     return items;
 }