doucha4054 2013-07-06 15:46
浏览 39
已采纳

如何检查facebook id是否有效[关闭]

I have a script which will generate random numbers like 1000089838938 but I need a solution to check if the generated number is associated with a valid facebook account.

Solution I am looking for should be in PHP.

Thanks.

  • 写回答

3条回答 默认 最新

  • drhzn3911 2013-07-06 15:55
    关注

    One solution is to check ID after generating via Graph API.

    http://graph.facebook.com/[ID]
    

    whatever ID is generated, put that at end of URL and check response received. Like if ID is 1303834107

    you can check @ http://graph.facebook.com/1303834107

    If it's correct, response will be something like:

    {
      "id": "1303834107",
      "name": "John Flake",
      "first_name": "John",
      "last_name": "Flake",
      "link": "https://www.facebook.com/john.flake",
      "username": "john.flake",
      "gender": "male",
      "locale": "en_US"
    }
    

    or if that ID is invalid, you will get something like:

    {
     "error": 
      {
      "message": "Unsupported get request.",
      "type": "GraphMethodException",
      "code": 100
      }
    }
    

    Based on response, you can validate that ID.

    Use php curl to call each time the API URL when ID is generated to check the response.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?