1

I'm developing an application for a client. This app enables user to read and post comment. Our client website have already used Discus. Now that we can retrieve the comment and display it natively. But we find no way to create a post and send it to Disqus. Does anyone have some experiences with Disqus on iOS ?

Any idea will be much appreciated.

Edit : our client website has an authentication system already and thus we also integrate that system to our app. Every time user post a comment in the app, we'll use his/her authentication information. We don't want user to authenticate again.

4

3 回答 3

2

这是一个很棒的解决方案,它有助于轻松地将 Disqus 集成到 iOS 应用程序中https://github.com/moqod/disqus-ios。像开箱即用的魅力一样工作。

您不仅可以发帖,还可以通过社交网络授权和回复评论。

于 2014-02-05T21:14:10.603 回答
1

您在服务器上设置了 API,对吗?然后向您的服务器发布一个请求,将您需要的任何 API 密钥和凭据传递给它,并让服务器代表客户端向 Disqus API 发布一个帖子。基本上,构建您自己的 iOS API 以通过您的服务器与 Disqus API 进行交互。

更好的是通过使用 NSURLRequest/Connection 发出请求来直接与 Disqus 服务器交互。有关 Disqus 请求的更多信息,请查看此处。这将使您的应用程序更快,更不容易出错,除非您在服务器上执行一些关键活动,而不仅仅是发布和显示评论。

于 2013-09-03T04:01:42.743 回答
0

@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];
于 2013-11-25T11:42:28.030 回答