Home > Mobile >  Issues publishing image to Facebook Page via Graph API SDK .NET
Issues publishing image to Facebook Page via Graph API SDK .NET

Time:12-22

Attempting this on .NET Core 3.1

After several hours of trying to publish a photo to my public facebook page (as in business page) of which I am the admin and have a long-term token for...

I keep getting the following response to my request using the official Facebook SDK for .NET. However, the image itself is never loaded.

{{"id":"786692942226147","post_id":"113260773923227_786692942226147"}}

The request looks like

                    var imageMedia = new FacebookMediaObject { FileName = file.FileName, ContentType = file.ContentType };
                    var stream = file.OpenReadStream();
                    var bytes = await stream.ReadAsByteArrayAsync();
                    imageMedia.SetValue(bytes);

                    var fbClient = new FacebookClient(credential.Token)
                    {
                        AppId = _config.GetValue<string>("FacebookClientId"),
                        AppSecret = _config.GetValue<string>("FacebookSecret")
                    };

                    dynamic parameters = new ExpandoObject();
                    parameters.message = request.Message;
                    parameters.file = imageMedia;

                    var result = await fbClient.PostTaskAsync($"{credential.PageId}/photos", parameters, token);

I'm sure it has something to do with the parameters I'm passing in, like parameters.file... but the docs for this thing are VERY unclear... as in "literally does not exist"

Anyone with experience getting this working, please point me in the right direction?

CodePudding user response:

The solution is to change parameters.file to parameters.image...

  • Related