gpt4 book ai didi

iphone - 尝试在 objective-c 中提交 Reddit 链接时生成的 error.USER_REQUIRED

转载 作者:行者123 更新时间:2023-11-29 13:38:48 24 4
gpt4 key购买 nike

我在这里遇到一个小的 Reddit API 问题。我正在尝试按照此处概述的 reddit api:

https://github.com/reddit/reddit/wiki/API

使用简单的 NSMutableURLRequest 登录不是问题:

NSString *user = [[NSString alloc]initWithString:[userFld text]];
NSString *passwd = [[NSString alloc]initWithString:[passwordFld text]];
NSString *urlString = [NSString stringWithFormat:@"http://www.reddit.com/api/login/username/?user=%@&passwd=%@",
[user stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[passwd stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

这给了我一个结果,我从中提取了用户 mod-hash:

4029916%2C2010-04-30T22%3A51%3A52%2C1243925043100000000000000000000000000000

接下来我尝试发布,使用:

NSString *redditUrlString = [NSString stringWithFormat:
@"http://www.reddit.com/api/submit/?uh=%@&kind=link&url=%@&sr=%@&title=%@&r=%@&api_type=json",
[appDelegate globalUhString],
@"www.google.com",
@"funny",
@"Google.com",
@"funny"];

NSURL *url = [NSURL URLWithString:redditUrlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

但是,当我从从此连接接收到的数据中提取 JSON 响应时,无论我使用什么作为 mod-hash,我总是收到以下错误:

[".error.USER_REQUIRED"]

谁能解释一下我做错了什么/我该如何解决?

最佳答案

看起来您没有将 reddit_session cookie 与 uh 参数一起传递。 api documentation似乎解释了收到错误的原因。根据this answer ,看起来您可能需要发出代码:

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

applicationDidBecomeActive 处理程序中,因为它可能会拒绝 cookie,因为 CookieAcceptPolicy 在所有应用程序之间共享。

关于iphone - 尝试在 objective-c 中提交 Reddit 链接时生成的 error.USER_REQUIRED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9751918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com