问题
I have a Slack App and Workspace. Since I am the admin, I can post the message to anyone and to any channel. But, when I am trying to post a message as a different user through an api call using the method chat.postMessage, it gives me the following response.
{"ok":false,"error":"missing_scope","needed":"chat:write:user","provided":"identity.basic,identity.email,identity.avatar,identity.team","warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}
I checked the Oauth and Permissions page on Slack and I have the scope as chat:write:user.
I cannot figure out what to do here. Could the auth tokens of the users restricted to be not able to post message and if so , how can I permit them to post message.
I also tried to open a direct message channel usin im.open method from the Slack documentation however, it provides a reasponse as under:
{"ok":false,"error":"missing_scope","needed":"im:write","provided":"identity.basic,identity.email,identity.avatar,identity.team"}
Again, when I check I already have im.open in the scope/permissions.
One last thing that I tried was I made another user as an admin,but it still says the same.
I am attaching my GetAccessToken method here. I think I am requesting the scope in the wrong manner or something like that.
public SlackAuthToken GetAccessToken(string clientId, string clientSecret, string code)
{
using (var client = new WebClient())
{
string oAuthUrl = "https://slack.com/oauth/authorize?client_id=" + clientId + "&scope=im%3Aread+chat%3Awrite%3Auser";
var authResponse = client.DownloadString(oAuthUrl);
string url ="https://xxx.slack.com/api/oauth.access?client_id=" + clientId + "&client_secret=" + clientSecret + "&code=" + code;
var response = client.DownloadString(url);
SlackAuthToken slackTest = JsonConvert.DeserializeObject<SlackAuthToken>(response);
string accessToken = slackTest.AccessToken;
string urlUserIdentity = "https://slack.com/api/users.identity?token=" + accessToken;
var responseUser = client.DownloadString(urlUserIdentity);
SlackAuthToken slack = JsonConvert.DeserializeObject<SlackAuthToken>(responseUser);
return slackTest;
}
}
来源:https://stackoverflow.com/questions/51332569/only-primary-owner-can-post-message-on-slack