AloSwift
AloSwift

Reputation: 407

How to use Google translator API V2 in iPhone Application?

Hi I am developing an iPhone application in which I am planing to implement some language translation functionality.I have purchased the google transilator API and got the API key. Now as per the the tutorial provided by Google I just made an HTTP call using ASIFormDataRequest to this URL "https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world". Unfortunately, it was ended up in an error called Access not configured. Is there any step that I missed ? please help me?

    ASIFormDataRequest *translateRequest = [ASIFormDataRequest requestWithURL:[ValidateClass getURL:@"Conversions.php"]];
    [translateRequest setDelegate:self];
    [translateRequest  setRequestMethod:@"GET"];
    [translateRequest setDidFinishSelector:@selector(didFinishRequest:)];
    [translateRequest setDidFailSelector:@selector(didFailRequest:)];
    [translateRequest setShouldAttemptPersistentConnection:NO];
    [translateRequest setTimeOutSeconds:120];
    [translateRequest startAsynchronous];

Upvotes: 1

Views: 717

Answers (1)

George
George

Reputation: 2187

Just get your Google key and plug it into the FGTranslator. After that it's a one-liner translate function call.

FGTranslator *translator = [[FGTranslator alloc] initWithGoogleAPIKey:@"your_google_key"];

[translator translateText:@"Bonjour!" 
               completion:^(NSError *error, NSString *translated, NSString *sourceLanguage)
{
    if (error)
        NSLog(@"translation failed with error: %@", error);
    else
        NSLog(@"translated from %@: %@", sourceLanguage, translated);
}];

Upvotes: 1

Related Questions