我从以下获取访问令牌
if ([FriendPeekerAppDelegate sharedDelegate].session.isOpen)
{
}
else
{
[FriendPeekerAppDelegate sharedDelegate].session = [[FBSession alloc] init];
[[FriendPeekerAppDelegate sharedDelegate].session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
// and here we make sure to update our UX according to the new session state
[self updateView];
}];
- (void)updateView
{
if ([FriendPeekerAppDelegate sharedDelegate].session.isOpen)
{
accessToken = [NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@",
[FriendPeekerAppDelegate sharedDelegate].session.accessTokenData.accessToken];
if (accessToken != nil)
{
self.accessToken = accessToken;
}
if ( (callbackObject != nil) && (callbackSelector != nil) )
{
[callbackObject performSelector:callbackSelector];
}
}
else
{
}
}
然后我想要回应
-(void)getMyInfo
{
FbGraphResponse *fb_graph_response = [self.fbGraph doGraphGet:@"me" withGetVars:nil];
NSString *tempStr = (NSString *)[fb_graph_response.htmlResponse retain];
id dict = [[CheckConnectionAndJsonParing singleton]jsonToFoundationRepresentation:tempStr];
}
- (FbGraphResponse *)doGraphGet:(NSString *)action withGetVars:(NSDictionary *)get_vars {
NSString *url_string = [NSString stringWithFormat:@"https://graph.facebook.com/%@?", action];
//tack on any get vars we have...
if ( (get_vars != nil) && ([get_vars count] > 0) ) {
NSEnumerator *enumerator = [get_vars keyEnumerator];
NSString *key;
NSString *value;
while ((key = (NSString *)[enumerator nextObject])) {
value = (NSString *)[get_vars objectForKey:key];
url_string = [NSString stringWithFormat:@"%@%@=%@&", url_string, key, value];
}//end while
}//end if
if (accessToken != nil) {
//now that any variables have been appended, let's attach the access token....
url_string = [NSString stringWithFormat:@"%@access_token=%@", url_string, self.accessToken];
}
//encode the string
url_string = [url_string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return [self doGraphGetWithUrlString:url_string];
}
- (FbGraphResponse *)doGraphGetWithUrlString:(NSString *)url_string {
FbGraphResponse *return_value = [[[FbGraphResponse alloc] init] autorelease];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url_string]];
NSError *err;
NSURLResponse *resp;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:&err];
if (resp != nil) {
/**
* In the case we request a picture (avatar) the Graph API will return to us the actual image
* bits versus a url to the image.....
**/
if ([resp.MIMEType isEqualToString:@"image/jpeg"]) {
UIImage *image = [UIImage imageWithData:response];
return_value.imageResponse = image;
} else {
NSString *stringResponse = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
return_value.htmlResponse = stringResponse;
[stringResponse release];
}
} else if (err != nil) {
return_value.error = err;
}
return return_value;
}
请给我建议.......