Пример #1
0
        /// <summary>
        /// 创建相册
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="userSecretKey"></param>
        /// <param name="userId"></param>
        public void CreateAlbum(string name, string description, string location, DownloadStringCompletedHandler callback)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = String.Format("{0}", DateTime.Now.Second);

            List <APIParameter> parameters = new List <APIParameter>();

            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("method", Method.CreateAlbum));
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("name", name));
            parameters.Add(new APIParameter("format", "JSON"));
            if (!string.IsNullOrEmpty(description))
            {
                parameters.Add(new APIParameter("description", description));
            }
            if (!string.IsNullOrEmpty(location))
            {
                parameters.Add(new APIParameter("location", location));
            }

            string sig = ApiHelper.CalSig(parameters);

            if (string.IsNullOrEmpty(sig))
            {
                return;
            }
            parameters.Add(new APIParameter("sig", sig));

            RenrenWebRequest createAlbumsAgent = new RenrenWebRequest();

            createAlbumsAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            createAlbumsAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
Пример #2
0
        //以下为详细版
        public void RequestAPIInterface(List <APIParameter> param, DownloadStringCompletedHandler callback)
        {
            List <APIParameter> parameters = new List <APIParameter>();

            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = String.Format("{0}", DateTime.Now.Second);

            //添加参数
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("format", "JSON"));

            foreach (APIParameter customParam in param)
            {
                parameters.Add(customParam);
            }

            //生成并添加sig参数
            string strSig = ApiHelper.CalSig(parameters);

            if (strSig == "")
            {
                return;
            }
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest webRequest = new RenrenWebRequest();//获取所有用户的

            //是否将参数转码utf-8
            webRequest.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            webRequest.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);//参数准确,从RequestUri下载数据
        }
        /// <summary>
        /// 得到当前登录用户的好友列表,带scope参数
        /// </summary>
        /// <param name="sessionkey">当前用户的session_key</param>
        /// <param name="userid">当前用户的id</param>
        /// <param name="callback">回调函数</param>
        /// <param name="scope">额外需要返回的字段,多个字段用逗号(,)隔开。目前支持如下字段: headurl_with_logo, tinyurl_with_logo</param>
        /// <param name="count">返回每页个数,默认为500</param>
        /// <param name="page">分页,默认为1</param>
        public void GetFriends(DownloadStringCompletedHandler callback,List<string> scope, int count ,int page)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = String.Format("{0}", DateTime.Now.Second);

            List<APIParameter> parameters = new List<APIParameter>() {
                new APIParameter("method",Method.GetFriends)
            };
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("userId", RenrenSDK.RenrenInfo.detailInfo.uid.ToString()));
            parameters.Add(new APIParameter("format", "JSON"));
            parameters.Add(new APIParameter("page", page.ToString()));
            if (count != 500) parameters.Add(new APIParameter("count", count.ToString()));
            if (scope != null && scope.Count > 0)
            {
                string[] arrScope = scope.ToArray<string>();
                parameters.Add(new APIParameter("fields", String.Join(" ", arrScope)));
            }
            string strSig = ApiHelper.CalSig(parameters);
            if (strSig == "")
                return;
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest getFriendsAgent = new RenrenWebRequest();
            getFriendsAgent.DownloadStringCompleted +=
                new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getFriendsAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
        /// <summary>
        /// 创建相册
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="userSecretKey"></param>
        /// <param name="userId"></param>
        public void CreateAlbum(string name, string description, string location, DownloadStringCompletedHandler callback)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = String.Format("{0}", DateTime.Now.Second);

            List<APIParameter> parameters = new List<APIParameter>();
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("method", Method.CreateAlbum));
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("name", name));
            parameters.Add(new APIParameter("format", "JSON"));
            if (!string.IsNullOrEmpty(description))
                parameters.Add(new APIParameter("description",description));
            if(!string.IsNullOrEmpty(location))
                parameters.Add(new APIParameter("location",location));

            string sig = ApiHelper.CalSig(parameters);
            if (string.IsNullOrEmpty(sig))
                return;
            parameters.Add(new APIParameter("sig", sig));

            RenrenWebRequest createAlbumsAgent = new RenrenWebRequest();

            createAlbumsAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            createAlbumsAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
        /// <summary>
        /// 获取指定用户相册列表 可扩展
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="userSecretKey"></param>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        public void GetAlbumList(int userId, DownloadStringCompletedHandler callback, int page, int count, string aids)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = String.Format("{0}", DateTime.Now.Second);

            List<APIParameter> parameters = new List<APIParameter>() { new APIParameter("method", Method.GetAlbums) };
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("uid", userId.ToString()));
            parameters.Add(new APIParameter("format", "JSON"));

            if (page != -1)
                parameters.Add(new APIParameter("page", page.ToString()));
            if (count != -1)
                parameters.Add(new APIParameter("count", count.ToString()));
            if(!string.IsNullOrEmpty(aids))
                parameters.Add(new APIParameter("aids", aids));
            string sig = ApiHelper.CalSig(parameters);
            if (string.IsNullOrEmpty(sig))
                return;
            parameters.Add(new APIParameter("sig", sig));

            RenrenWebRequest getAlbumsAgent = new RenrenWebRequest();
            getAlbumsAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getAlbumsAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
Пример #6
0
        /// <summary>
        /// 得到当前登录用户的用户信息
        /// </summary>
        /// <param name="sig">签名认证。是用当次请求的所有参数计算出来的值</param>
        /// <param name="method">users.getLoggedInUser</param>
        /// <param name="v">API的版本号,固定值为1.0</param>


        public void GetCurUserInfo(DownloadStringCompletedHandler callback)
        {
            List <APIParameter> parameters = new List <APIParameter>()
            {
                new APIParameter("method", "users.getLoggedInUser")//获取当前用户ID
            };
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = String.Format("{0}", DateTime.Now.Second);

            //添加其他参数
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("format", "JSON"));

            //生成并添加sig参数
            string strSig = ApiHelper.CalSig(parameters);

            if (strSig == "")
            {
                return;
            }
            parameters.Add(new APIParameter("sig", strSig));


            RenrenWebRequest getCurUserInfoAgent = new RenrenWebRequest();

            //是否将参数转码utf-8
            getCurUserInfoAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getCurUserInfoAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
Пример #7
0
        /// <summary>
        /// 执行接口方法
        /// 传入参数列表,比如接口名字,format形式等
        /// </summary>
        /// <param name="paras">参数列表</param>
        /// <returns>服务器响应数据</returns>
        public void CallMethod(List <APIParameter> paras, List <APIParameter> files)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = DateTime.Now.Millisecond.ToString();

            if (paras == null || paras.Count == 0)
            {
                throw new ArgumentNullException("paras required");
            }
            if (files == null || files.Count == 0)
            {
                throw new ArgumentNullException("files required");
            }

            paras.Add(new APIParameter("call_id", DateTime.Now.Millisecond.ToString()));
            paras.Add(new APIParameter("access_token", accessToken));
            paras.Add(new APIParameter("v", "1.0"));
            paras.Add(new APIParameter("format", "JSON"));
            string strSig = ApiHelper.CalSig(paras);

            if (strSig == "")
            {
                return;
            }
            paras.Add(new APIParameter("sig", strSig));
            RenrenWebRequest client = new RenrenWebRequest();

            client.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(client_DownloadStringCompleted);
            client.DownloadStringAsyncWithFile(ConstantValue.RequestUri.ToString(), paras, files);
        }
Пример #8
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        public void LogIn(string username, string password, List <string> scope,
                          DownloadStringCompletedHandler callback)
        {
            List <APIParameter> parameters = new List <APIParameter>()
            {
                new APIParameter("method", "admin.getAllocation")
            };

            parameters.Add(new APIParameter("grant_type", "password"));
            parameters.Add(new APIParameter("username", username));
            parameters.Add(new APIParameter("password", password));
            parameters.Add(new APIParameter("client_id", ConstantValue.ApiKey));
            parameters.Add(new APIParameter("client_secret", ConstantValue.SecretKey));

            if (scope != null && scope.Count > 0)
            {
                string[] arrScope = scope.ToArray <string>();
                parameters.Add(new APIParameter("scope", String.Join(" ", arrScope)));
            }

            RenrenWebRequest logInAgent = new RenrenWebRequest();

            logInAgent.DownloadStringCompleted +=
                new RenrenWebRequest.DownloadStringCompletedHandler(callback);

            logInAgent.DownloadStringAsync(ConstantValue.OAuthUri.ToString(), parameters);
        }
        /// <summary>
        /// 得到当前登录用户的用户信息
        /// </summary>
        /// <param name="sig">签名认证。是用当次请求的所有参数计算出来的值</param>
        /// <param name="method">users.getLoggedInUser</param>
        /// <param name="v">API的版本号,固定值为1.0</param>
        public void GetCurUserInfo(DownloadStringCompletedHandler callback)
        {
            List<APIParameter> parameters = new List<APIParameter>()
            {
                new APIParameter("method","users.getLoggedInUser")//获取当前用户ID
            };
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = String.Format("{0}",DateTime.Now.Second);

            //添加其他参数
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("format", "JSON"));

            //生成并添加sig参数
            string strSig = ApiHelper.CalSig(parameters);
            if (strSig == "")
                return;
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest getCurUserInfoAgent = new RenrenWebRequest();
            //是否将参数转码utf-8
            getCurUserInfoAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getCurUserInfoAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
Пример #10
0
        //以下为详细版
        public void RequestAPIInterface(List<APIParameter> param, DownloadStringCompletedHandler callback)
        {
            List<APIParameter> parameters = new List<APIParameter>();

            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = String.Format("{0}", DateTime.Now.Second);

            //添加参数
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("format", "JSON"));

            foreach (APIParameter customParam in param)
            {
                parameters.Add(customParam);
            }

            //生成并添加sig参数
            string strSig = ApiHelper.CalSig(parameters);
            if (strSig == "")
                return;
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest webRequest = new RenrenWebRequest();//获取所有用户的
            //是否将参数转码utf-8
            webRequest.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            webRequest.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);//参数准确,从RequestUri下载数据
        }
Пример #11
0
        /// <summary>
        /// 执行接口方法
        /// 传入参数列表,比如接口名字,format形式等
        /// </summary>
        /// <param name="paras">参数列表</param>
        /// <returns>服务器响应数据</returns>
        public void CallMethod(List<APIParameter> paras, List<APIParameter> files)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = DateTime.Now.Millisecond.ToString();

            if (paras == null || paras.Count == 0) throw new ArgumentNullException("paras required");
            if (files == null || files.Count == 0) throw new ArgumentNullException("files required");

            paras.Add(new APIParameter("call_id", DateTime.Now.Millisecond.ToString()));
            paras.Add(new APIParameter("access_token", accessToken));
            paras.Add(new APIParameter("v", "1.0"));
            paras.Add(new APIParameter("format", "JSON"));
            string strSig = ApiHelper.CalSig(paras);
            if (strSig == "")
                return;
            paras.Add(new APIParameter("sig", strSig));
            RenrenWebRequest client = new RenrenWebRequest();
            client.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(client_DownloadStringCompleted);
            client.DownloadStringAsyncWithFile(ConstantValue.RequestUri.ToString(), paras, files);
        }
Пример #12
0
        //以下为详细版
        public void GetUserInfo(List <string> scope, DownloadStringCompletedHandler callback, List <int> uids = null)
        {
            List <APIParameter> parameters = new List <APIParameter>()
            {
                new APIParameter("method", Method.GetInfo)//获取当前用户ID
            };

            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = String.Format("{0}", DateTime.Now.Second);

            //添加其他参数
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("format", "JSON"));
            if (scope != null && scope.Count > 0)
            {
                string[] arrScope = scope.ToArray <string>();
                parameters.Add(new APIParameter("fields", String.Join(" ", arrScope)));
            }
            if (uids != null && uids.Count > 0)
            {
                int[] uid = uids.ToArray <int>();
                parameters.Add(new APIParameter("uids", String.Join(",", uid)));
            }

            //生成并添加sig参数
            string strSig = ApiHelper.CalSig(parameters);

            if (strSig == "")
            {
                return;
            }
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest getUsersInfoAgent = new RenrenWebRequest();//获取所有用户的

            //是否将参数转码utf-8
            getUsersInfoAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getUsersInfoAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);//参数准确,从RequestUri下载数据
        }
Пример #13
0
        /// <summary>
        /// 获取指定用户相册列表 可扩展
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="userSecretKey"></param>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        public void GetAlbumList(int userId, DownloadStringCompletedHandler callback, int page, int count, string aids)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = String.Format("{0}", DateTime.Now.Second);

            List <APIParameter> parameters = new List <APIParameter>()
            {
                new APIParameter("method", Method.GetAlbums)
            };

            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("uid", userId.ToString()));
            parameters.Add(new APIParameter("format", "JSON"));

            if (page != -1)
            {
                parameters.Add(new APIParameter("page", page.ToString()));
            }
            if (count != -1)
            {
                parameters.Add(new APIParameter("count", count.ToString()));
            }
            if (!string.IsNullOrEmpty(aids))
            {
                parameters.Add(new APIParameter("aids", aids));
            }
            string sig = ApiHelper.CalSig(parameters);

            if (string.IsNullOrEmpty(sig))
            {
                return;
            }
            parameters.Add(new APIParameter("sig", sig));

            RenrenWebRequest getAlbumsAgent = new RenrenWebRequest();

            getAlbumsAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getAlbumsAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
Пример #14
0
        /// <summary>
        /// 得到当前登录用户的好友列表,带scope参数
        /// </summary>
        /// <param name="sessionkey">当前用户的session_key</param>
        /// <param name="userid">当前用户的id</param>
        /// <param name="callback">回调函数</param>
        /// <param name="scope">额外需要返回的字段,多个字段用逗号(,)隔开。目前支持如下字段: headurl_with_logo, tinyurl_with_logo</param>
        /// <param name="count">返回每页个数,默认为500</param>
        /// <param name="page">分页,默认为1</param>
        public void GetFriends(DownloadStringCompletedHandler callback, List <string> scope, int count, int page)
        {
            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID      = String.Format("{0}", DateTime.Now.Second);

            List <APIParameter> parameters = new List <APIParameter>()
            {
                new APIParameter("method", Method.GetFriends)
            };

            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("userId", RenrenSDK.RenrenInfo.detailInfo.uid.ToString()));
            parameters.Add(new APIParameter("format", "JSON"));
            parameters.Add(new APIParameter("page", page.ToString()));
            if (count != 500)
            {
                parameters.Add(new APIParameter("count", count.ToString()));
            }
            if (scope != null && scope.Count > 0)
            {
                string[] arrScope = scope.ToArray <string>();
                parameters.Add(new APIParameter("fields", String.Join(" ", arrScope)));
            }
            string strSig = ApiHelper.CalSig(parameters);

            if (strSig == "")
            {
                return;
            }
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest getFriendsAgent = new RenrenWebRequest();

            getFriendsAgent.DownloadStringCompleted +=
                new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getFriendsAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);
        }
        //以下为详细版
        public void GetUserInfo(List<string> scope, DownloadStringCompletedHandler callback, List<int> uids = null)
        {
            List<APIParameter> parameters = new List<APIParameter>()
            {
                new APIParameter("method",Method.GetInfo)//获取当前用户ID
            };

            string accessToken = RenrenSDK.RenrenInfo.tokenInfo.access_token;
            string callID = String.Format("{0}", DateTime.Now.Second);

            //添加其他参数
            parameters.Add(new APIParameter("v", "1.0"));
            parameters.Add(new APIParameter("access_token", accessToken));
            parameters.Add(new APIParameter("call_id", callID));
            parameters.Add(new APIParameter("format", "JSON"));
            if (scope != null && scope.Count > 0)
            {
                string[] arrScope = scope.ToArray<string>();
                parameters.Add(new APIParameter("fields", String.Join(" ", arrScope)));
            }
            if (uids != null && uids.Count > 0)
            {
                int[] uid = uids.ToArray<int>();
                parameters.Add(new APIParameter("uids", String.Join(",", uid)));
            }

            //生成并添加sig参数
            string strSig = ApiHelper.CalSig(parameters);
            if (strSig == "")
                return;
            parameters.Add(new APIParameter("sig", strSig));

            RenrenWebRequest getUsersInfoAgent = new RenrenWebRequest();//获取所有用户的
            //是否将参数转码utf-8
            getUsersInfoAgent.DownloadStringCompleted += new RenrenWebRequest.DownloadStringCompletedHandler(callback);
            getUsersInfoAgent.DownloadStringAsync(ConstantValue.RequestUri.ToString(), parameters);//参数准确,从RequestUri下载数据
        }
Пример #16
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        public void LogIn(string username, string password, List<string> scope, 
            DownloadStringCompletedHandler callback)
        {
            List<APIParameter> parameters = new List<APIParameter>() {
                new APIParameter("method","admin.getAllocation")
            };
            parameters.Add(new APIParameter("grant_type", "password"));
            parameters.Add(new APIParameter("username", username));
            parameters.Add(new APIParameter("password", password));
            parameters.Add(new APIParameter("client_id", ConstantValue.ApiKey));
            parameters.Add(new APIParameter("client_secret", ConstantValue.SecretKey));

            if (scope != null && scope.Count > 0)
            {
                string[] arrScope = scope.ToArray<string>();
                parameters.Add(new APIParameter("scope", String.Join(" ", arrScope)));
            }

            RenrenWebRequest logInAgent = new RenrenWebRequest();
            logInAgent.DownloadStringCompleted +=
                new RenrenWebRequest.DownloadStringCompletedHandler(callback);

            logInAgent.DownloadStringAsync(ConstantValue.OAuthUri.ToString(), parameters);
        }