简体   繁体   中英

search user in uiwebview as a logged in user in facebook

I am integrating app with facebook. I am getting user info and publish_stream permission. After user logs in user can search other user directly from UIWebView . I was able to do so when there is accessToken. Using this i was showing other user's profile as current user.

storing in variable when user logs in for future purpose.

url =[NSString stringWithFormat:@"https://facebook.com/search/results.php?q=SEARCH_USER&type=user&access_token=%@",self.selectedMatch.realName,facebookAccessToken];

But, now as access token is deprecated there is accessTokenData . But I am not able to show it as a current user, it directly takes user to facebook login page. Any one knows how i can do this using the latest SDK of facebook ?

I tried with this but it display facebook login screen.

url =[NSString stringWithFormat:@"https://facebook.com/search/results.php?q=NAME&type=user&access_token=ACCESS_TOKEN"];

accessTokenData is of type FBAccessTokenData and has a property accessToken which is a NSString. Just use this as you used the access token before and it should work I guess:

url =[NSString stringWithFormat:@"https://facebook.com/search/results.php?q=NAME&type=user&access_token=%@", accessTokenData.accessToken];

Here's some more info on that topic: Facebook: Making API Calls to Publish with an App Access Token

You have to log into facebook now to request private information regarding an account, this was changed so that your apps can't get user information with out permission from the user. So you have a main user

[FBSession activeSession]

and with that main user you ask for information. Such as their friends list:

 FBRequest* friendsRequest = [FBRequest requestForMyFriends];

 [friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary* result, NSError *error) {

 }];

this code defaults to using the token data which is associated with the session object aka in this example

[[FBSession activeSession] accessTokenData]

for using the graph api to access any random person's facebook to see the public data you can do this by the below code using Mark Zuckerberg's facebook the founder of facebook as the example https://www.facebook.com/pages/Mark-Zuckerberg/112845672063384

FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession
                                                      graphPath:@"112845672063384"];
[newConnection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
   NSDictionary* facebookUserPublicInfo = (NSSDictionary*)result;
}];
[newConnection start]

I guess i've never actually had to use the access token data in methods, it was always assumed to be that of the activeSession, but if you did the access token data IS the access token they just renamed it and it might carry other meta data

The way Facebook works has been changed. You have everything you need here : https://developers.facebook.com/ios/ .

The part that you want is probably this one : https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/show-friends/ .

I have done by specifying web view as default behavior like this.

[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:
    ^(FBSession *session,FBSessionState state,NSError *error)
    {
        if(state == FBSessionStateOpen)
       {
        // code when login is successful.
       }
    }];

If you are using webview for user to login then you can display any specific as logged in user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM