Great – this worked. In my installation the line
$permissions = array(‘offline_access’, ‘share_item’);
is actually on line 1325
and
preg_match(‘/^.+=\s*(.+)/’, $access_token_url, $matches);
was on line 1187
although these were the only instances of these two bits of code and changing them as outlined above got this working.