- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用来自 google reader's API 的数据开发应用程序并使用 GData用于登录。
我希望能够将表格单元格内的帖子标记为已读/未读,但我发现这主要是未记录的,很难找到解决方案,有什么想法/链接吗?
这是标记已读按钮的代码:
//Get the token
NSString *tokenString = [NSString stringWithFormat:@"https://www.google.com/reader/api/0/token"];
NSURL *tokenURL = [NSURL URLWithString:tokenString];
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
NSString *tokenStringResult;
NSArray *listItems;
NSError *tokenError = nil;
NSURLResponse *tokenResponse = nil;
NSData *tokenData = [NSURLConnection sendSynchronousRequest:tokenRequest
returningResponse:&tokenResponse
error:&tokenError];
if (tokenData)
{
tokenStringResult = [[NSString alloc] initWithData:tokenData encoding:NSUTF8StringEncoding];
listItems = [tokenStringResult componentsSeparatedByString:@"/"];
}
else
{
NSLog(@"tokenError = %@", tokenError);
}
// Mark it as read
NSString *readerURLString = [NSString stringWithFormat:@"http://www.google.com/reader/api/0/edit-tag?a=user/-/state/com.google/read&async=true&s=feed/%@&i=%@&T=%@", siteLink, postID, [listItems lastObject]];
NSURL *readerURL = [NSURL URLWithString:readerURLString];
NSMutableURLRequest *readerRequest = [NSMutableURLRequest requestWithURL:readerURL];
[mAuth authorizeRequest:readerRequest];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:readerRequest
returningResponse:&response
error:&error];
if (data)
{
NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response;
assert( [httpResponse isKindOfClass:[NSHTTPURLResponse class]] );
NSLog(@"response.allHeaderFields = %@", [httpResponse allHeaderFields]);
NSLog(@"response.statusCode = %i", [httpResponse statusCode]);
}
日志是这样的:
response.statusCode = {
"Cache-Control" = "private, max-age=0";
"Content-Length" = 1334;
"Content-Type" = "text/html; charset=UTF-8";
Date = "Fri, 21 Jan 2011 03:49:07 GMT";
Expires = "Fri, 21 Jan 2011 03:49:07 GMT";
Server = GSE;
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = SAMEORIGIN;
"X-Reader-Google-Version" = "527-000";
"X-Reader-User" = 01940378872835844713;
"X-Xss-Protection" = "1; mode=block";
}
response.statusCode = 400
最佳答案
所以通过大量的试验和错误,我让它工作了。
编辑 - 添加授权码
NSString *GOOGLE_CLIENT_AUTH_URL = @"https://www.google.com/accounts/ClientLogin?client=SomeName";
NSString *gSourceString = @"SomeName";
NSMutableURLRequest *httpReq = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:GOOGLE_CLIENT_AUTH_URL]];
[httpReq setTimeoutInterval:30.0];
[httpReq setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[httpReq setHTTPMethod:@"POST"];
[httpReq addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString *requestBody = [[NSString alloc] initWithFormat:@"Email=%@&Passwd=%@&service=reader&accountType=HOSTED_OR_GOOGLE&source=%@", userString, passwordString, [NSString stringWithFormat:@"%@%d", gSourceString]];
[httpReq setHTTPBody:[requestBody dataUsingEncoding:NSASCIIStringEncoding]];
[requestBody release];
NSHTTPURLResponse *response = nil;
NSData *data = nil;
NSString *responseStr = nil;
NSArray *responseLines = nil;
int responseStatus = 0;
data = [NSURLConnection sendSynchronousRequest:httpReq returningResponse:&response error:&error];
[httpReq release];
if ([data length] > 0)
{
responseStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
responseStatus = [response statusCode];
if (responseStatus == 200 )
{
authOK = TRUE;
NSLog(@"Successfully authenticated with Google.");
NSArray *authLines = nil;
authLines = [responseStr componentsSeparatedByString:@"\n"];
int j;
for (j =0; j < [authLines count]; j++ )
{
if ([[authLines objectAtIndex:j] rangeOfString:@"Auth="].length != 0) {
NSMutableString *teststring = [NSMutableString stringWithString:[authLines objectAtIndex:j]];
[teststring replaceCharactersInRange:NSMakeRange(0,4) withString:@"auth"];
authString = teststring;
}
}
}
}
NSString *auth = [[NSString alloc] initWithString: [NSString stringWithFormat:@"GoogleLogin %@", authString]];
NSDictionary *createHeader = [[NSDictionary dictionaryWithObjectsAndKeys:@"www.google.com", @"Host", @"EditApp", @"User-Agent", @"gzip, deflate", @"Accept-Encoding", auth, @"Authorization", nil]retain];
[auth release];
NSURL *url =[NSURL URLWithString:@"http://www.google.com/reader/api/0/token?client=EditApp"];
NSData *recieveData;
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]initWithURL:url];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setAllHTTPHeaderFields:createHeader];
NSURLResponse *response;
NSError *error;
recieveData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
// Get token
NSString *pretokenString = [[NSString alloc] initWithData:recieveData encoding:NSASCIIStringEncoding];
tokenString = [pretokenString substringWithRange:NSMakeRange(2, [pretokenString length]-2)];
[pretokenString release];
[urlRequest release];
NSMutableURLRequest *thttpReq = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.google.com/reader/api/0/edit-tag?"]];
[thttpReq setTimeoutInterval:30.0];
[thttpReq setHTTPMethod:@"POST"];
NSString *authHeader = [NSString stringWithFormat:@"GoogleLogin %@", authString];
[thttpReq addValue:authHeader forHTTPHeaderField:@"Authorization"];
[thttpReq addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
// siteLink is the url of the feed
// googlePostID is the id from the XML output: tag:google.com,2005:reader/item/e3345c69e174bdec
NSString *trequestBody = [[NSString alloc] initWithFormat:@"a=user/-/state/com.google/read&ac=edit-tags&s=feed/%@&i=%@&T=%@", siteLink, googlePostID, tokenString];
[thttpReq setHTTPBody:[trequestBody dataUsingEncoding:NSASCIIStringEncoding]];
NSURLConnection *con = [[NSURLConnection alloc]
initWithRequest:thttpReq
delegate:self
startImmediately:NO];
[con scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
[con start];
关于iphone - 在 iphone 谷歌阅读器应用程序中将项目标记为已读/未读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4720232/
我正在尝试实现类似于电子邮件中的已读/未读的功能。我如何通过使用 jquery、php 和 mysql 来实现。我想分步执行的操作: 1- 当我单击 html 表中的一行时,我更改了此消息在数据库中的
如何确定消息状态(已读/未读)。聊天是通过 XMPP 协议(protocol)实现的。 最佳答案 XEP-0184 : Message Delivery Receipts 支持在消息已送达时通知发件人
上下文:我们正在实现一个新闻应用程序。现在,您可以假设所有用户的新闻都是相同的,并根据我们设置的参数(根据趋势和日期)维护订单。 问题:我们不确定跟踪用户阅读内容的最佳实现是什么。我们希望能够配置一种
好吧,另一个有趣的问题是 50 号公路。 我们想实现一个真正的论坛灯泡系统,其中用户未读的帖子(在创建用户帐户后)显示为未读,直到该状态被清除或直到用户阅读它们。 我们认为最好和最简单的方法是实现一个
我正在使用来自 google reader's API 的数据开发应用程序并使用 GData用于登录。 我希望能够将表格单元格内的帖子标记为已读/未读,但我发现这主要是未记录的,很难找到解决方案,有什
我的 C 程序已从 Linux 上的 TCP 套接字读取(使用 read(2) 或 recv(2))几个字节。是否可以将这些字节推回,以便后续的 read(2) 和 recv(2) 调用(在我无法控制
我是一名优秀的程序员,十分优秀!