我一直在尝试将Instagram API集成到我的应用程序中,但我仍然坚持使用身份验证 . 当我刚刚使用隐式流版本时,我让它完全正常工作,它给了我access_token作为URI片段的一部分 . 但是,现在我改为服务器端流程,我在用户登录后收到代码 . 然后我将这些代码发布到访问令牌URL,然后会给我access_token以及有关的某些信息 . 用户,例如他们的用户名和 Profiles 图片链接 .
我正在使用InstaSharp库,修改源代码 .
HttpClient client = new HttpClient { BaseAddress = new Uri(config.OAuthUri + "access_token/", UriKind.Absolute) };
var request = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress);
request.AddParameter("client_secret", config.ClientSecret);
request.AddParameter("client_id", config.ClientId);
request.AddParameter("grant_type", "authorization_code");
request.AddParameter("redirect_uri", config.RedirectUri);
request.AddParameter("code", code);
return client.ExecuteAsync<OAuthResponse>(request);
创建请求后,其格式如下:{方法:POST,RequestUri:'https://api.instagram.com/oauth/access_token/?client_secret= &client_id = &grant_type = authorization_code&redirect_uri = http://instagram.com&code = ', Version: 1.1, Content: , Headers: { }} (I inserted the space between the redirect_uri and code because it wouldn' t让我发布问题否则)
地址中的所有内容都显示正常,但我总是在重新调整的json文件中收到错误:
“{”code“:400,”error_type“:”OAuthException“,”error_message“:”您必须提供client_id“}”
我不知道造成这个错误的原因 . 任何帮助是极大的赞赏!谢谢!埃利奥特
1 回答
您使用的是最新版本的InstaSharp吗?叉吧here . 您可以在那里查看README.md,尽管's a bit outdated and you need to tweak some config. Here'是如何使用github中的最新版本来完成的:
请注意,您可以拆分“instagramauth”方法 . 这样做是为了简洁 .