简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM