Родное приложение Google Reader для iPhone

В настоящее время я занимаюсь созданием родного приложения Google Reader для iPhone, похожего на успешное приложение «Reeder for iPhone», но с полным встроенным клиентом Twitter.

Я закончил клиент Twitter и теперь пытаюсь запустить клиент Google Reader. Я просмотрел несколько документов и взглянул на образцы gdata-objective-client, но до сих пор не могу понять, что мне нужно сделать, чтобы реализовать ту же функциональность, что и Reeder.

В основном я хочу иметь возможность предоставить пользователю экран входа в систему. Затем пользователь отправляет свои учетные данные и токен доступа, и все это делается за кулисами, как и с xAuth в Twitter. Затем я хочу нажать контроллер представления, который показывает UITableView со всеми текущими непрочитанными каналами. Когда пользователь щелкает UITableViewCell, соответственно выдвигается подробное представление, содержащее содержимое сообщений.

Возможно ли это, и если да, то как мне реализовать эти функции? Я был бы признателен, если бы люди публиковали «фрагменты кода» и действительно показывали, как они добиваются реализации.

Заранее спасибо!

РЕДАКТИРОВАТЬ: Мне было доведено до сведения, что движок приложения Google не нужен. Однако вопрос все равно остается прежним. Как мне внедрить Google Reader в свое приложение?


person Sebastien Peek    schedule 27.09.2010    source источник
comment
почему это помечено как google-app-engine?   -  person Thilo    schedule 27.09.2010
comment
потому что из того, что я прочитал, нужно как-то реализовать движок приложения Google? если вы не можете помочь и указать мне в правильном направлении?   -  person Sebastien Peek    schedule 27.09.2010
comment
App Engine — это инфраструктура для создания веб-приложений — она не имеет ничего общего с чисто клиентским приложением для iPhone.   -  person Nick Johnson    schedule 27.09.2010
comment
Как мне тогда внедрить Google Reader API в свое приложение?   -  person Sebastien Peek    schedule 27.09.2010


Ответы (3)


Это было так просто. Для всех, кто интересуется, чтобы подключиться к Google Reader API, я сделал следующее.

/*  Google clientLogin API:
     Content-type: application/x-www-form-urlencoded
     Email=userName
     Passwd=password
     accountType=HOSTED_OR_GOOGLE
     service=xapi
     source = @"myComp-myApp-1.0"
     */

    //define our return objects
    BOOL authOK;
    NSString *authMessage = [[NSString alloc] init];
    NSArray *returnArray = nil;
    //begin NSURLConnection prep:
    NSMutableURLRequest *httpReq = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:GOOGLE_CLIENT_AUTH_URL] ];
    [httpReq setTimeoutInterval:30.0];
    //[httpReq setCachePolicy:NSURLRequestReloadIgnoringCacheData];
    [httpReq setHTTPMethod:@"POST"];
    //set headers
    [httpReq addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
    //set post body
    NSString *requestBody = [[NSString alloc] 
                             initWithFormat:@"Email=%@&Passwd=%@&service=reader&accountType=HOSTED_OR_GOOGLE&source=%@",
                             gUserString, gPassString, [NSString stringWithFormat:@"%@%d", gSourceString]];

    [httpReq setHTTPBody:[requestBody dataUsingEncoding:NSASCIIStringEncoding]];

    NSHTTPURLResponse *response = nil;
    NSError *error = nil;
    NSData *data = nil;
    NSString *responseStr = nil;
    NSArray *responseLines = nil;
    NSString *errorString;
    //NSDictionary *dict;
    int responseStatus = 0;
    //this should be quick, and to keep same workflow, we'll do this sync.
    //this should also get us by without messing with threads and run loops on Tiger.
    data = [NSURLConnection sendSynchronousRequest:httpReq returningResponse:&response error:&error];

    if ([data length] > 0) {
        responseStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
        //NSLog(@"Response From Google: %@", responseStr);
        responseStatus = [response statusCode];
        //dict = [[NSDictionary alloc] initWithDictionary:[response allHeaderFields]];
        //if we got 200 authentication was successful
        if (responseStatus == 200 ) {
            authOK = TRUE;
            authMessage = @"Successfully authenticated with Google. You can now start viewing your unread feeds.";
        }
        //403 = authentication failed.
        else if (responseStatus == 403) {
            authOK = FALSE;
            //get Error code.
            responseLines  = [responseStr componentsSeparatedByString:@"\n"];
            //find the line with the error string:
            int i;
            for (i =0; i < [responseLines count]; i++ ) {
                if ([[responseLines objectAtIndex:i] rangeOfString:@"Error="].length != 0) {
                    errorString = [responseLines objectAtIndex:i] ;
                }
            }

            errorString = [errorString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            /*
             Official Google clientLogin Error Codes:
             Error Code Description
             BadAuthentication  The login request used a username or password that is not recognized.
             NotVerified    The account email address has not been verified. The user will need to access their Google account directly to resolve the issue before logging in using a non-Google application.
             TermsNotAgreed The user has not agreed to terms. The user will need to access their Google account directly to resolve the issue before logging in using a non-Google application.
             CaptchaRequired    A CAPTCHA is required. (A response with this error code will also contain an image URL and a CAPTCHA token.)
             Unknown    The error is unknown or unspecified; the request contained invalid input or was malformed.
             AccountDeleted The user account has been deleted.
             AccountDisabled    The user account has been disabled.
             ServiceDisabled    The user's access to the specified service has been disabled. (The user account may still be valid.)
             ServiceUnavailable The service is not available; try again later.
             */

            if ([errorString  rangeOfString:@"BadAuthentication" ].length != 0) {
                authMessage = @"Please Check your Username and Password and try again.";
            }else if ([errorString  rangeOfString:@"NotVerified"].length != 0) {
                authMessage = @"This account has not been verified. You will need to access your Google account directly to resolve this";
            }else if ([errorString  rangeOfString:@"TermsNotAgreed" ].length != 0) {
                authMessage = @"You have not agreed to Google terms of use. You will need to access your Google account directly to resolve this";
            }else if ([errorString  rangeOfString:@"CaptchaRequired" ].length != 0) {
                authMessage = @"Google is requiring a CAPTCHA response to continue. Please complete the CAPTCHA challenge in your browser, and try authenticating again";
                //NSString *captchaURL = [responseStr substringFromIndex: [responseStr rangeOfString:@"CaptchaURL="].length]; 
                //either open the standard URL in a browser, or show a custom sheet with the image and send it back...
                //parse URL to append to GOOGLE_CAPTCHA_URL_PREFIX
                //but for now... just launch the standard URL.
                //[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:GOOGLE_CAPTCHA_STANDARD_UNLOCK_URL]];         
            }else if ([errorString  rangeOfString:@"Unknown" ].length != 0) {
                authMessage = @"An Unknow error has occurred; the request contained invalid input or was malformed.";
            }else if ([errorString  rangeOfString:@"AccountDeleted" ].length != 0) {
                authMessage = @"This user account previously has been deleted.";
            }else if ([errorString  rangeOfString:@"AccountDisabled" ].length != 0) {
                authMessage = @"This user account has been disabled.";
            }else if ([errorString  rangeOfString:@"ServiceDisabled" ].length != 0) {
                authMessage = @"Your access to the specified service has been disabled. Please try again later.";
            }else if ([errorString  rangeOfString:@"ServiceUnavailable" ].length != 0) {
                authMessage = @"The service is not available; please try again later.";
            }

        }//end 403 if

    }
    //check most likely: no internet connection error:
    if (error != nil) {
        authOK = FALSE;
        if ( [error domain]  == NSURLErrorDomain) {
            authMessage = @"Could not reach Google.com. Please check your Internet Connection";
        }else {
            //other error
            authMessage = [authMessage stringByAppendingFormat:@"Internal Error. Please contact notoptimal.net for further assistance. Error: %@", [error localizedDescription] ];
        }
    }
    //NSLog (@"err localized description %@", [error localizedDescription]) ;
    //NSLog (@"err localized failure reasons %@", [error localizedFailureReason]) ;
    //NSLog(@"err code  %d", [error code]) ;
    //NSLog (@"err domain %@", [error domain]) ;


    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Authentication" message:authMessage delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
    [alertView show];
    [alertView release];

    [gUserString    release];
    [gPassString    release];
    [gSourceString  release];

    [authMessage    release];

}

}

Очевидно, я использовал своих собственных делегатов и тому подобное, но это общее желание/ощущение, которое я привнес в свое приложение.

В настоящее время я работаю над переносом непрочитанных каналов/элементов в UITableView для отображения в моем RootViewController. Я обновлю это с дополнительной информацией.

Спасибо всем, кто пытался помочь :D

person Sebastien Peek    schedule 30.09.2010
comment
спасибо за это решение, я неделями рвал на себе волосы по этому поводу - person daihovey; 24.01.2011

СПАСИБО. Я знал, что есть простой способ войти в систему, но мне было ужасно трудно понять его. Кстати, для тех из вас, кто копирует/вставляет код the0rkus выше - вы получите несколько ошибок. Чтобы проверить это, я добавил:

NSString *gUserString = @"[email protected]";
NSString *gPassString = @"yourpassword";
NSString *GOOGLE_CLIENT_AUTH_URL = @"https://www.google.com/accounts/ClientLogin?client=YourClient";
NSString *gSourceString = @"YourClient";
person Designeveloper    schedule 06.10.2010
comment
Откуда я могу получить GOOGLE_CLIENT_AUTH_URL и gSourceString??? Нужно ли мне регистрировать свое приложение где-то на сайте Google? - person Shri; 19.11.2011

Погуглите, есть много блогов, в которых описывается, как использовать Google Reader API. Вот достойная отправная точка: http://mindsharestrategy.com/google-reader-api-a-brief-tutorial/

person Abhijit Rao    schedule 27.09.2010
comment
Они объясняют, как использовать его с Python, вряд ли кто-то подробно расскажет об использовании его с Objective-C... - person Sebastien Peek; 27.09.2010
comment
@the0rkus - Это руководство написано на PHP, а не на Python. Но он должен быть очень переносимым. API использует стандартные пары HTTP-запрос/ответ для связи, так что на самом деле вам просто нужно знать, как делать запросы GET/POST и как анализировать ответы в Objective-C. Если вы этого не сделаете, вам следует изучить это, прежде чем пытаться взаимодействовать с каким-либо внешним API. - person EAMann; 17.05.2011