Facebook将照片上传为公司页面 [英] facebook upload photo as company page

查看:108
本文介绍了Facebook将照片上传为公司页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用Facebook图形API(OAuth)上传照片有疑问.

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);
            }
        }

推荐答案

为了代表Page使用Graph API,您需要获取Page访问令牌-有关更多详细信息,请参见此处:

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. 验证用户身份并请求manage_pages权限
  2. 从(1)获取用户管理的页面列表: https://graph .facebook.com/me/accounts?access_token = USER_ACCESS_TOKEN
  3. 解析列表并获取令牌-并将其发布到供稿中.

您将在图形API资源管理器中执行(1)-您将获得用户令牌.然后将该令牌插入(2)中的URL中-您将看到所有页面和相应的令牌.拿一个您需要的图片,然后在C#代码中使用它上传图片.

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.

这篇关于Facebook将照片上传为公司页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆