florianv / snoop
查找电子邮件地址所有者的信息
v1.0.0
2014-06-13 23:47 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- guzzle/guzzle: ~3.0
- phpunit/phpunit: ~3.7
Suggests
- guzzle/guzzle: If you want to use the Guzzle3Adapter
- guzzlehttp/guzzle: If you want to use the Guzzle4Adapter
This package is auto-updated.
Last update: 2024-09-05 00:20:15 UTC
README
⚠️ 此工具目前损坏,因为Rapportive最近更改了它们的API,所以这个技巧不再可用。
Snoop可以找到有关电子邮件地址所有者的信息,例如其姓名、社交档案、图片和职位。
安装
将此行添加到您的composer.json
文件中
{ "require": { "florianv/snoop": "~1.0" } }
当前支持Guzzle 3和4的HTTP客户端,因此您需要要求其中之一
"guzzle/guzzle": "~3.0"
"guzzlehttp/guzzle": "~4.0"
用法
您可以在这里找到一个使用它的简单示例
首先,您需要创建一个适配器
// If you use Guzzle 3 $adapter = new \Snoop\Adapter\Guzzle3Adapter(new \Guzzle\Http\Client()); // If you use Guzzle 4 $adapter = new \Snoop\Adapter\Guzzle4Adapter(new \GuzzleHttp\Client());
然后您可以创建一个Snoop实例并使用它
// Create a Snoop instance $snoop = new \Snoop\Snoop($adapter); // Find the person with email 'john@doe.com' $person = $snoop->find('john@doe.com'); $person->getFirstName(); // John $person->getLastName(); // Doe $person->getLocation(); // San Francisco Bay Area $person->getHeadline(); // Developer at Google foreach ($person->getImages() as $url) {} foreach ($person->getJobs() as $job) { $job->getTitle(); // Developer $job->getCompanyName(); // Google } foreach ($person->getProfiles() as $profile) { $profile->getSiteName(); // Twitter $profile->getUsername(); // johndoe }
默认情况下,将发出两个请求:一个用于获取令牌,另一个用于获取信息,但您可以分别发送它们
// Fetch a token, maybe store it somewhere $token = $snoop->fetchToken(); // Find the informations using the token $person = $snoop->find('hello@world.com', $token);
异常处理
InvalidTokenException
当令牌丢失或无效时,会抛出InvalidTokenException
。
try { $snoop->find('hello@world.com'); } catch (Snoop\Exception\InvalidTokenException $e) { // You might fetch a new token and retry }
PersonNotFoundException
当与电子邮件相关的数据不存在时,会抛出PersonNotFoundException
。
try { $snoop->find('hello@world.com'); } catch (Snoop\Exception\PersonNotFoundException $e) { // This person was not found }