You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular/JS/Ionic中Facebook、LinkedIn用户检索及位置获取技术问询

Solutions for User Search & Location Retrieval in Angular/Ionic/JavaScript

LinkedIn User Search (Name/Phone/Email)

LinkedIn offers a People Search API that lets you query users by name, email, or phone—provided you have the right permissions. Here’s how to implement this in your Angular/Ionic app:

  • First, secure the necessary scopes: r_liteprofile (for basic profile data), r_emailaddress (if searching by email), and for business-focused use cases, rw_organization_admin (though most standard user searches only need the first two).
  • Use Angular’s HttpClient to send requests to LinkedIn’s API:
import { HttpClient } from '@angular/common/http';

constructor(private http: HttpClient) {}

searchLinkedInUsers(query: string, type: 'name' | 'email' | 'phone') {
  const accessToken = 'YOUR_LINKEDIN_ACCESS_TOKEN';
  let searchParam = '';
  
  switch(type) {
    case 'email':
      searchParam = `email:${query}`;
      break;
    case 'phone':
      searchParam = `phone:${query}`;
      break;
    default:
      const nameParts = query.split(' ');
      searchParam = `firstName:${nameParts[0]},lastName:${nameParts[1] || ''}`;
  }

  return this.http.get(`https://api.linkedin.com/v2/people-search?q=${searchParam}`, {
    headers: { 'Authorization': `Bearer ${accessToken}` }
  });
}

Keep in mind: LinkedIn’s API has rate limits, and certain scopes require app approval. Make sure to review their policy guidelines before deploying to production.

Facebook User Search: Alternatives to Deprecated APIs

Unfortunately, Facebook’s Graph API no longer supports public user search by name, phone, or email—this was phased out years ago due to strict privacy regulations. Here are practical workarounds:

  • Login + Verification Flow: Instead of searching for users, ask them to log in with Facebook, then verify their email/phone against your existing database. This lets you link accounts without public searching.
  • Business-Focused Marketing API: If you’re building a business tool, Facebook’s Marketing API offers targeted audience features, but this is restricted to business accounts and requires explicit approval.
  • Fetch User Profile Post-Login: Once a user logs in, you can retrieve their own profile details (name, email, phone) using the email and user_phone_number permissions (if granted). Example using the Facebook SDK in Ionic:
window.FB.login(function(response) {
  if (response.authResponse) {
    window.FB.api('/me', {fields: 'name,email,phone'}, function(user) {
      console.log('User profile:', user);
      // Match this data against your database records
    });
  }
}, {scope: 'email,user_phone_number'});

Retrieving User Visited Locations Post-Login

To get a user’s location data (current city, hometown, or visited places) from Facebook, you’ll need specific permissions:

  • user_location: Access to the user’s current city
  • user_hometown: Access to their hometown
  • user_visited_places: Access to specific places they’ve visited (restricted to apps with approved use cases like travel or local services)

Example Implementation in Ionic/Angular:

  1. Initialize the Facebook SDK in your app:
window.fbAsyncInit = function() {
  window.FB.init({
    appId      : 'YOUR_FB_APP_ID',
    cookie     : true,
    xfbml      : true,
    version    : 'v18.0'
  });
};

// Load SDK asynchronously
(function(d, s, id){
   var js, fjs = d.getElementsByTagName(s)[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement(s); js.id = id;
   js.src = "https://connect.facebook.net/en_US/sdk.js";
   fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
  1. Fetch location data after login:
window.FB.login(function(response) {
  if (response.authResponse) {
    window.FB.api('/me', {fields: 'location,hometown,visited_places'}, function(response) {
      console.log('User location data:', response);
    });
  }
}, {scope: 'user_location,user_hometown,user_visited_places'});

Sample Facebook Response (as provided):

{
"location": {
"id": "123456789",
"name": "New York, New York"
},
"hometown": {
"id": "987654321",
"name": "Boston, Massachusetts"
},
// Visited places data appears here if permission is granted
}

Note: The user_visited_places permission requires Facebook’s review and is only allowed for apps that fit specific use cases. Ensure your app’s purpose aligns with their policies before applying.


内容的提问来源于stack exchange,提问作者Shyam Nair

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:39:02