facebook upload photo as company page

白昼怎懂夜的黑 提交于 2020-01-03 05:24:06

问题


I have a question regarding using facebook graph API (OAuth) to upload photo.

I have created one company page under my account.

When I use my account to upload photo to my company page, my user name appears as a user who uploaded the page.

Is there anyway I can upload page so that company name appears?

Below is the code that I currently implemented.

        string access_token = FacebookSystem.RetrieveToken(UserEmail, AppID);

        string query = string.Empty;

        if (string.IsNullOrEmpty(PageID) || PageID.Equals("default", StringComparison.InvariantCultureIgnoreCase))
        {
            query = "me/photos";  
        }
        else
        {
            query = string.Format("{0}/photos", PageID); 
        }

        var fb = new FacebookClient(access_token);

        try
        {
            dynamic parameters = new ExpandoObject();

            foreach (string i in args.FileList)
            {
                parameters.message = args.Comment;
                parameters.source = new FacebookMediaObject
                {
                    ContentType = "image",
                    FileName = Path.GetFileName(i)
                }.SetValue(File.ReadAllBytes(i));

                fb.Post(query, parameters);
            }
        }

回答1:


in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens

  1. Authenticate the user and request the manage_pages permission
  2. Get the list of pages the user manages from (1): https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
  3. Parse the list and get the token - and use it to post to the feed.

you will do (1) in graph API explorer - and you will get user token. Then insert that token into URL in (2) - and you will see all your pages and corresponding token. Take the one you need and use it in your C# code to upload images.



来源:https://stackoverflow.com/questions/19824901/facebook-upload-photo-as-company-page

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