我正在尝试使用gmail api阅读gmail邮件,并在阅读邮件后,我正在删除邮件标签,这样我就不需要再次处理它了。我能够成功阅读邮件,但是当我尝试修改邮件标签时
(service.Users.Messages.Modify(mods, userId, messageId).Execute();
)
然后我收到错误消息:
发生错误:Google.Apis.Requests.RequestError
许可不足[403]
错误[
消息[权限不足]位置[ - ]原因[不足的佩尔米斯
sions]域[global]>
]。
我无法弄明白,可能出了什么问题? 提前谢谢。
答案 0 :(得分:5)
您需要将权限添加到范围变量和 然后删除文件storedCredentials(C:\ Users \ Administrateur.credentials .. )
答案 1 :(得分:1)
我在使用服务帐户API密钥的控制台应用程序中遇到了类似的问题。添加完所有必要的范围后,如上面的Tholle所述,必须使用Google管理控制台中的必要权限更新应用程序。为此,请确保转到管理控制台并删除当前应用并再次执行该程序以获取具有更新范围的新权限的新令牌。
实现同样目标的另一种方法是执行上面提到的Mohamed。这是从" ...用户\ [用户名] \。凭证\ [apiCredentialName] .json"中删除JSON文件。夹。这将强制应用程序进行身份验证并获取新令牌。希望这有助于一些人: - )
答案 2 :(得分:1)
我通过更改Scopes变量解决了这个问题。我假设您从QuickStart模板开始,该模板仅允许只读访问。您可以如下更改范围:
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
message = 'When the mutton and an omelet had been served and a samovar and vodka brought, with some wine which the French had taken from a Russian cellar and brought with them, Ramballe invited Pierre to share his dinner, and himself began to eat greedily and quickly like a healthy and hungry man, munching his food rapidly with his strong teeth, continually smacking his lips, and repeating- Excellent! Delicious! His face grew red and was covered with perspiration. Pierre was hungry and shared the dinner with pleasure. Morel, the orderly, brought some hot water in a saucepan and placed a bottle of claret in it. He also brought a bottle of kvass, taken from the kitchen for them to try. That beverage was already known to the French and had been given a special name. They called it limonade de cochon (pigs lemonade), and Morel spoke well of the limonade de cochon he had found in the kitchen. But as the captain had the wine they had taken while passing through Moscow, he left the kvass to Morel and applied himself to the bottle of Bordeaux. He wrapped the bottle up to its neck in a table napkin and poured out wine for himself and for Pierre. The satisfaction of his hunger and the wine rendered the captain still more lively and he chatted incessantly all through dinner'
key1 = 11
key2 = 3
def affine(message, key1, key2):
for m in message:
output = ''
if m.upper() not in ALPHABET:
output += m
continue
index = ALPHABET.find(m.upper())
newIndex = (index * key1 + key2) % len(ALPHABET)
output += ALPHABET.find(newIndex)
return output
提醒:在更改范围并删除了certificate.json后,请再次从gmail api重新验证您的访问权限。
希望它对您有用!