async public Task <JsonArray> UploadMultiplePhotosAsync(List <Dictionary <string, object> > parameters)
        {
            try
            {
                FacebookBatchParameter[] batchArray = new FacebookBatchParameter[parameters.Count];
                for (int i = 0; i < parameters.Count; i++)
                {
                    batchArray[i] = new FacebookBatchParameter(HttpMethod.Post, base.pageID + "/photos", parameters[i]);
                }

                dynamic result = await fb.BatchTaskAsync(batchArray);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        private async void BatchRequestExample()
        {
            try
            {
                dynamic result = await _fb.BatchTaskAsync(
                    new FacebookBatchParameter { HttpMethod = HttpMethod.Get, Path = "/4" },
                    new FacebookBatchParameter(HttpMethod.Get, "/me/friend", new Dictionary <string, object> {
                    { "limit", 10 }
                }),                                                                                                                                        // this should throw error
                    new FacebookBatchParameter("/me/friends", new { limit = 1 }) { Data = new { name = "one-friend", omit_response_on_success = false } }, // use Data to add additional parameters that doesn't exist
                    new FacebookBatchParameter { Parameters = new { ids = "{result=one-friend:$.data.0.id}" } },
                    new FacebookBatchParameter("{result=one-friend:$.data.0.id}/feed", new { limit = 5 }),
                    new FacebookBatchParameter().Query("SELECT name FROM user WHERE uid="),                                                       // fql
                    new FacebookBatchParameter().Query("SELECT first_name FROM user WHERE uid=me()", "SELECT last_name FROM user WHERE uid=me()") // fql multi-query
                    //,new FacebookBatchParameter(HttpMethod.Post, "/me/feed", new { message = "test status update" })
                    );

                // always remember to check individual errors for the batch requests.
                if (result[0] is Exception)
                {
                    // handle error message // MessageBox.Show(((Exception)result[0]).Message);
                    return;
                }

                dynamic first = result[0];
                string  name  = first.name;

                // note: incase the omit_response_on_success = true, result[x] == null

                // for this example, just comment it out.
                //if (result[1] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
                //if (result[2] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
                //if (result[3] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
                //if (result[4] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
                //if (result[5] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
                //if (result[6] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
                //if (result[7] is Exception)
                //    MessageBox.Show(((Exception)result[1]).Message);
            }
            catch (FacebookApiException ex)
            {
                // handle error message
            }
        }
        public object UploadFaceBookBatch(FacebookPosting input)
        {
            try
            {
                var fb = new FacebookClient(input.FacebookToken);
                fb.AppId     = input.FacebookAppId;
                fb.AppSecret = input.FacebookAppSecret;
                List <FacebookBatchParameter> fbp = new List <FacebookBatchParameter>();

                int count = 0;
                foreach (var item in input.PostingItems)
                {
                    string extension = Path.GetExtension(item.url);
                    string FileName  = Path.GetFileName(item.url);

                    if (!string.IsNullOrEmpty(extension))
                    {
                        extension = extension.Replace(".", "");
                    }

                    var param = new FacebookBatchParameter(HttpMethod.Post, "/me/photos", new Dictionary <string, object> {
                        { "message", item.Title }, { "pic" + count, new FacebookMediaObject {
                                                         ContentType = "image/" + extension, FileName = FileName
                                                     }.SetValue(File.ReadAllBytes(item.url)) }
                    });
                    fbp.Add(param);
                    count++;
                }

                return(fb.BatchTaskAsync(fbp.ToArray()).Result);
            }
            catch (FacebookOAuthException ex)
            {
                Console.WriteLine(ex.Message);
                return(ex);
            }
            catch (FacebookApiException ex)
            {
                Console.WriteLine(ex.Message);
                return(ex);
            }
        }