You may use [hook_flag_access()][1], as in the following code.


     function crystal_qa_flag_access($flag, $entity_id, $action, $account) {
       // Only the author of the question has right to use flag "Accepeted" on answers.
       if (($flag->name == 'accepted') && ($flag->content_type == 'node')  && ($node = node_load($entity_id))) {
         if ($node->type=='answer') {
           // The content type machine name must be answer.
           $question_nid = $node->field_answer['und']['0']['target_id'];
           $question = node_load($question_nid);
           return ($question->uid == $account->uid);
         }
       }
     }






  [1]: http://drupalcontrib.org/api/drupal/contributions%21flag%21flag.api.php/function/hook_flag_access/7