@RahuGupta:抱歉,如果回复太晚了。我使用 SSO 发表评论,我不知道以访客身份发表评论。但这应该更容易。
就我而言,我使用第三方身份验证服务器发表评论,这意味着我们自己对用户进行身份验证。该技术称为 SSO。您可能需要阅读有关 Disqus 上的 SSO 的文档。
如果您需要 Objective-c 中的代码片段:
NSMutableDictionary *dico = [[NSMutableDictionary alloc] init];
[dico setValue:[NSString stringWithFormat:@"uniqueId_%@",comment.authorID] forKey:@"id"];
[dico setValue:comment.authorName forKey:@"username"];
[dico setValue:comment.authorEmail forKey:@"email"];
NSString *message = [dico JSONRepresentation];
NSString *message64Based = [DataPost base64String:message];
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
NSString *secret = DISQUS_API_SECRET;
NSString *api_key = DISQUS_API_PUBLIC;
//comment.threadID will makes the app crashed, because when comment is not fully loaded, it's nil
NSString *threadID = [NSString stringWithFormat:@"%@",comment.threadID];
NSString *commentMessage = [[comment.rawMessage stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSString *host = @"http://example.com";
NSString *referrer = @"example.com";
NSString *hmac = [self hashedValue:secret andData:[NSString stringWithFormat:@"%@ %.0lf",message64Based, timeStamp]];
NSString *remote_auth_s3 = [[[NSString stringWithFormat:@"%@ %@ %.0lf", message64Based, hmac, timeStamp] stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSMutableURLRequest *uploadRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://disqus.com/api/3.0/posts/create.json"] cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 60.0f];
NSMutableData *postData = (NSMutableData *)[[NSString stringWithFormat:@"_format=json&thread=%@&message=%@&remote_auth=%@&api_key=%@&strict=1", threadID , commentMessage, remote_auth_s3 , api_key] dataUsingEncoding:NSUTF8StringEncoding];
[uploadRequest setHTTPMethod:@"POST"];
[uploadRequest setHTTPBody: postData];
[uploadRequest setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[uploadRequest setValue:referrer forHTTPHeaderField:@"referrer"];
[uploadRequest setValue:host forHTTPHeaderField:@"host"];
[uploadRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSHTTPURLResponse *response=nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:uploadRequest returningResponse:&response error:&error];