public static int getPostNumber(long mUser, string accessToken) { long highestInt = 10000000; string parameters = "owner_id=" + mUser + "&count=100&offset=" + highestInt.ToString(); string wallRespond = getMethodData("wall.get", parameters, accessToken, "5.69", "yes"); RootPostsObject vkPostsOfmUser = null; var jss = new JavaScriptSerializer(); try { vkPostsOfmUser = jss.Deserialize <RootPostsObject>(wallRespond); } catch { vkPostsOfmUser = new RootPostsObject(); vkPostsOfmUser.response.count = 0; Log("Posts request error happened", "log.txt"); } return(vkPostsOfmUser.response.count); }
public static List <FlatPost> getAllPostLikeFriendmUser(long mUser, string access_token) { var jss = new JavaScriptSerializer(); int count = 1; int iteration = 0; int offset = 0; int itemsCount = 0; var vkPostsOfmUser = new RootPostsObject(); List <RootPostsObject> vkAllPostsOfmUser = new List <RootPostsObject>(); List <Items[]> vkAllPostsItemsOfmUser = new List <Items[]>(); List <FlatPost> flatPost = new List <FlatPost>(); string parameters = "user_id=" + mUser; string friendsRespond = getMethodData("friends.get", parameters, access_token, "5.69", "yes"); if (friendsRespond.Contains("error_code")) { return(null); } Log("friends request:" + friendsRespond, "log.txt"); var vkFriendsOfmUser = new RootObject(); try { vkFriendsOfmUser = jss.Deserialize <RootObject>(friendsRespond); } catch { Log("Friends request error happened", "log.txt"); } string[] mUserFriends = vkFriendsOfmUser.response.items; itemsCount = getPostNumber(mUser, access_token); Console.WriteLine("mUserFriends count={0}", mUserFriends.Count()); while (offset < itemsCount) { List <PostPerUser> postUser = new List <PostPerUser>(); Console.WriteLine("mUser={0}", mUser); Console.WriteLine("iteration={0}", iteration); Log("mUser:"******"log.txt"); Log("iteration:" + iteration, "log.txt"); parameters = "owner_id=" + mUser + "&count=100&offset=" + (iteration * 100).ToString(); string wallRespond = getMethodData("wall.get", parameters, access_token, "5.69", "yes"); using (SqlConnection openCon = new SqlConnection("Data Source=DESKTOP-HTB4CGJ;Initial Catalog=VkAnalysis;Integrated Security=SSPI;")) { byte[] byteArray = Encoding.ASCII.GetBytes(wallRespond); string saveStaff = "INSERT into stg.[vkRespond] (response, requestType) VALUES (@binaryValue,'Wall')"; using (SqlCommand querySaveStaff = new SqlCommand(saveStaff)) { querySaveStaff.Connection = openCon; openCon.Open(); try { querySaveStaff.Parameters.Add("@binaryValue", SqlDbType.VarBinary, -1).Value = byteArray; querySaveStaff.ExecuteNonQuery(); } catch { Log("mUser:"******"log.txt"); } openCon.Close(); } } Log("Wall request:" + wallRespond, "log.txt"); /*try * { * vkPostsOfmUser = jss.Deserialize<RootPostsObject>(wallRespond); * } * catch * { * Log("Posts request error happened", "log.txt"); * }*/ //vkAllPostsOfmUser.Add(vkPostsOfmUser); //vkAllPostsItemsOfmUser.Add(vkPostsOfmUser.response.items); /*for (int i = 0; i < vkPostsOfmUser.response.items.Count(); i++) * { * postUser.Add(new PostPerUser(vkPostsOfmUser.response.items.ElementAt(i).id, mUser, vkPostsOfmUser.response.items.ElementAt(i).likes.count)); * flatPost.Add(new FlatPost(vkPostsOfmUser.response.items.ElementAt(i).id, vkPostsOfmUser.response.items.ElementAt(i).from_id * , vkPostsOfmUser.response.items.ElementAt(i).owner_id, vkPostsOfmUser.response.items.ElementAt(i).date * , vkPostsOfmUser.response.items.ElementAt(i).text, vkPostsOfmUser.response.items.ElementAt(i).likes.count)); * }*/ // itemsCount = vkPostsOfmUser.response.items.Count(); //count = vkPostsOfmUser.response.count; offset = iteration * 100; iteration++; //save posts into a file // get Likes for each Post for a current user //getAllLikes(mUser, access_token, postUser); } /*if(mUserFriends.Count() > 99) * { * int countTot = mUserFriends.Count(); * decimal loopsDec = mUserFriends.Count() / 100; * int loops = Convert.ToInt32(Math.Truncate(loopsDec)); * * //List<string[]> mUserFriendsList = new List<string[]>(); * * for (int i = 0; i < loops; i++ ){ * string[] mUserFriendsList = new string[100]; * int end = Math.Min(countTot, (i * 100) + 100); * int counter = 0; * for (int j = i * 100; j < end; j++) * { * mUserFriendsList[counter] = mUserFriends[j]; * counter++; * } * getAllFriends(mUser, mUserFriendsList, access_token); * } * } * else * { * getAllFriends(mUser, mUserFriends, access_token); * }*/ return(flatPost); }