Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
907 views
in Technique[技术] by (71.8m points)

ios - Swift Open Facebook Profile by FacebookUID

I'm trying to open a user's Facebook profile in Swift using their Facebook UID. In the Simulator, it works and opens up the web version of the profile and works fine, however on my actual device, it opens up the Facebook native app and gives me a "Page not Found" error.

guard let facebookUID = self.user?.facebookUID else {
    return
}

print(facebookUID)
let fbURLWeb: NSURL = NSURL(string: "https://www.facebook.com/(facebookUID)")!
let fbURLID: NSURL = NSURL(string: "fb://profile/(facebookUID)")!

if(UIApplication.sharedApplication().canOpenURL(fbURLID)){
    // FB installed
    UIApplication.sharedApplication().openURL(fbURLID)
} else {
    // FB is not installed, open in safari
    UIApplication.sharedApplication().openURL(fbURLWeb)
}

enter image description here

What am I doing wrong?

Thanks in advance!

EDIT

I've noticed that if a user deletes or doesn't have the Facebook app installed on their phone, it will open up the profile correctly through Safari, which is why it worked on the simulator, but didn't on my device. However, I've also noticed I can get it to work in the Facebook app if I try a public profile like fb://profile/4 (which is Mark Zuckerburg's profile).

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hi based on documentation Facebook ID is the App-scoped User ID so you can use like

fb://profile?app_scoped_user_id=%@

But also check bug report on https://developers.facebook.com/bugs/332195860270199 opening the Facebook profile with

fb://profile?app_scoped_user_id=%@

is not supported.

So you will have to open the Facebook profile within Safari or you can use in app webview to open user profile. I have check with some facebook id 10000****889,10000***041 etc. all have open profile in facebook app.Yes some have same error.Page bot found.

May be there is Privacy setting->Do you want search engine outside link to your profile->No. restrict search.

To get ids of user from facebook Trick :

1)Right click on the person or page's profile photo, select properties and the ID will be included in the page

2)In mobile browswe if you open photo there is id E.g. " fbid = *** & pid = 1000....89 " so 1000....89 will be your user id


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...