简体   繁体   English

Instagram Api 通过标记获取用户名时出现令牌错误

[英]Instagram Api Token Error While Getting Username With Tagging

I'm trying to get the username of the owner of the picture I'm tagged in. However, when I try to go to my request url, taking error below.我正在尝试获取我被标记的图片所有者的用户名。但是,当我尝试 go 到我的请求 url 时,出现以下错误。 Researched about this case but couldn't find something useful about this situation.研究了这种情况,但找不到有关这种情况的有用信息。

{ "error": { "message": "Invalid OAuth access token - Cannot parse access token", "type": "OAuthException", "code": 190, "fbtrace_id": "ALI1tNJ_alXBJmnJWK-w0vq" } } { “错误”:{ “消息”:“无效的 OAuth 访问令牌 - 无法解析访问令牌”,“类型”:“OAuthException”,“代码”:190,“fbtrace_id”:“ALI1tNJ_alXBJmnJWK-w0vq”}}

`

By the way when I try to get my profile media's and other fields, having no trouble about that. Here's my source codes:


 public class SocialFeedService
    {
        private readonly string instagramBaseAPIUrl = "https://graph.instagram.com/";
        private readonly string facebookBaseAPIUrl = "https://graph.facebook.com/";

        public string GetInstagramContents(string userToken)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    string mediaUrl = $"me/media?fields=id,tags,mentions,username,timestamp,caption,media_url,media_type,permalink&access_token={userToken}";
                    string tagUrl = $"me/tags?fields=id,username&access_token={userToken}";

                    string fullMediaUrl = $"{this.instagramBaseAPIUrl}{mediaUrl}";
                    string fullTagUrl = $"{this.facebookBaseAPIUrl}{tagUrl}";

                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var response = client.GetStringAsync(new Uri(fullTagUrl)).Result;

                    if (!string.IsNullOrEmpty(response))
                    {
                        var result = response;
                        return result;
                    }

                    return string.Empty;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
     }

And here is my controller :

 public class XControllers : ControllerBase
    {
        IConfiguration configuration;

        public XControllers(IConfiguration configuration)
        {
            this.configuration = configuration;
        }
       

        [HttpGet]
        public IActionResult Get()
        {
            string token = @"IG...";

            var service = new SocialFeedService();
            string result = service.GetInstagramContents(token);


            return Ok(result);
        }
    }

Thanks in advance.




Just trying to take tagged media owner's username. 

There could be several reasons why you receive an invalid token error for OAuth. I would recommend ruling out a few of the following:您收到 OAuth 的invalid token错误的原因可能有多种。我建议排除以下几种情况:

  • access_token wasn't properly passed in the Authorization header access_token未在授权中正确传递 header
  • An invalid access_token was used (included a typo, invalid string, etc.)使用了无效的access_token (包括拼写错误、无效字符串等)
  • The access_token was expired (typically lasts for 1 hour) access_token已过期(通常持续 1 小时)

You might also find this guide on OAuth Troubleshooting tips helpful.您可能还会发现有关OAuth 故障排除提示的本指南很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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