mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-25 09:43:41 +00:00
[twitter] Use existing contact fields instead of guessing in twitter_unfollow
- Add `friendship/destroy` API call result logging
This commit is contained in:
parent
5769d99478
commit
b732cf8968
1 changed files with 3 additions and 8 deletions
|
@ -177,16 +177,10 @@ function twitter_follow(App $a, array &$contact)
|
||||||
function twitter_unfollow(App $a, array &$hook_data)
|
function twitter_unfollow(App $a, array &$hook_data)
|
||||||
{
|
{
|
||||||
$contact = $hook_data['contact'];
|
$contact = $hook_data['contact'];
|
||||||
Logger::info('Check if contact is twitter contact', ['url' => $contact["url"]]);
|
if ($contact['netword'] !== Protocol::TWITTER) {
|
||||||
|
|
||||||
if (!strstr($contact["url"], "://twitter.com") && !strstr($contact["url"], "@twitter.com")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// contact seems to be a twitter contact, so continue
|
|
||||||
$nickname = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $contact["url"]);
|
|
||||||
$nickname = str_replace("@twitter.com", "", $nickname);
|
|
||||||
|
|
||||||
$uid = $a->getLoggedInUserId();
|
$uid = $a->getLoggedInUserId();
|
||||||
|
|
||||||
$ckey = DI::config()->get('twitter', 'consumerkey');
|
$ckey = DI::config()->get('twitter', 'consumerkey');
|
||||||
|
@ -201,7 +195,8 @@ function twitter_unfollow(App $a, array &$hook_data)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
|
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
|
||||||
$connection->post('friendships/destroy', ['screen_name' => $nickname]);
|
$result = $connection->post('friendships/destroy', ['screen_name' => $contact['nick']]);
|
||||||
|
Logger::info('[twitter] API call "friendship/destroy" successful', ['result' => $result]);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
Logger::notice('[twitter] API call "friendships/destroy" failed', ['uid' => $uid, 'url' => $contact['url'], 'exception' => $e]);
|
Logger::notice('[twitter] API call "friendships/destroy" failed', ['uid' => $uid, 'url' => $contact['url'], 'exception' => $e]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue