Can I upload photos to a wall belonging to a fan (company) page wall using the Facebook Graph API?

送分小仙女□ 提交于 2020-01-01 19:12:21

问题


I need to know if it's possible to make it so authorized users can upload photos to a fan page of a company (to the wall) using the graph API. Also, is it possible to become like (become a fan) of a company page through the api once the user is authorized.


回答1:


Yes you can. You need to obtain your admin access token by using the Graph API explorer (https://developers.facebook.com/tools/explorer) and with a call to

https://graph.facebook.com/{adminfacebookid}/accounts

this will list all pages and apps your admin has access to. Look for the fan page in question and copy the accessToken.

Next get the albumid by clicking on the id of the page, then adding /albums to the request

armed with this you can then post the image data to the url, using the facebook web client

like this

protected void PublishToPublicGallery(string accessToken, string filename, long albumId, string imagename)
        {

            var facebookClient = new FacebookClient(accessToken);
            var mediaObject = new FacebookMediaObject
            {
                FileName = filename,
                ContentType = "image/jpeg"
            };
            var fileBytes = System.IO.File.ReadAllBytes(filename);
            mediaObject.SetValue(fileBytes);

            IDictionary<string, object> upload = new Dictionary<string, object>();
            upload.Add("name", imagename);
            upload.Add("source", mediaObject);
            var result = facebookClient.Post("/" + albumId + "/photos", upload) as JsonObject;    
        }


来源:https://stackoverflow.com/questions/2780278/can-i-upload-photos-to-a-wall-belonging-to-a-fan-company-page-wall-using-the-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!