iphone - I have integrated google plus in my IOS App , Now how can i get profile detail of logged in user? -
i have integrated google plus in ios app ,i able access token.i have used authentication flow integrate google plus.so after getting access token how can user profile details username, email id, profile pic etc? code access token below:
-(ibaction)btngoogleplusclicked:(uibutton *)sender
{ ibwebview.hidden = false;
nsstring *url = [nsstring stringwithformat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%@&redirect_uri=%@&scope=%@&data-requestvisibleactions=%@",google_plus_client_id,google_plus_call_back_url,google_plus_scope,google_plus_visible_actions]; [ibwebview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:url]]];
} - (bool)webview:(uiwebview*)webview shouldstartloadwithrequest:(nsurlrequest*)request navigationtype:(uiwebviewnavigationtype)navigationtype { // [indicator startanimating]; if ([[[request url] host] isequaltostring:@"localhost"]) {
// extract oauth_verifier url query nsstring* verifier = nil; nsarray* urlparams = [[[request url] query] componentsseparatedbystring:@"&"]; (nsstring* param in urlparams) { nsarray* keyvalue = [param componentsseparatedbystring:@"="]; nsstring* key = [keyvalue objectatindex:0]; if ([key isequaltostring:@"code"]) { verifier = [keyvalue objectatindex:1]; nslog(@"verifier %@",verifier); break; } } if (verifier) { nsstring *data = [nsstring stringwithformat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,google_plus_client_id,google_plus_client_secret,google_plus_call_back_url]; nsstring *url = [nsstring stringwithformat:@"https://accounts.google.com/o/oauth2/token"]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:url]]; [request sethttpmethod:@"post"]; [request sethttpbody:[data datausingencoding:nsutf8stringencoding]]; nsurlconnection *theconnection=[[nsurlconnection alloc] initwithrequest:request delegate:self]; receiveddata = [[nsmutabledata alloc] init]; } else { // error! } [webview removefromsuperview]; return no; } return yes;
}
- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { [receiveddata appenddata:data]; nslog(@"verifier %@",receiveddata); } - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error{ uialertview *alert = [[uialertview alloc] initwithtitle:@"error" message:[nsstring stringwithformat:@"%@", error] delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alert show]; } - (void)connectiondidfinishloading:(nsurlconnection *)connection { nsstring *response = [[nsstring alloc] initwithdata:receiveddata encoding:nsutf8stringencoding]; sbjsonparser *jresponse = [[sbjsonparser alloc]init]; nsdictionary *tokendata = [jresponse objectwithstring:response]; // webservicesocket *dconnection = [[webservicesocket alloc] init]; // dconnection.delegate = self; nsstring *pdata = [nsstring stringwithformat:@"type=3&token=%@&secret=123&login=%@", [tokendata objectforkey:@"refresh_token"], self.islogin]; // nsstring *pdata = [nsstring stringwithformat:@"type=3&token=%@&secret=123&login=%@",[tokendata accesstoken.secret,self.islogin]; // [dconnection fetch:1 withpostdata:pdata withgetdata:@"" issilent:no]; uialertview *alertview = [[uialertview alloc] initwithtitle:@"google access token" message:pdata delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; }
i feel the method using not profile detail.
i suggest use proper method ensures best results.
please check out : https://developers.google.com/+/mobile/ios/
this surely required outcome.
Comments
Post a Comment