Google Cloud API - Application Default Credentials

前端 未结 5 1376
借酒劲吻你
借酒劲吻你 2021-02-04 07:04

I have the following code, modified from Google\'s documentation:

        $GOOGLE_APPLICATION_CREDENTIALS = \"./[path].json\";
        $_ENV[\"GOOGLE_APPLICATION         


        
5条回答
  •  旧巷少年郎
    2021-02-04 07:08

    I agree with the above answer, but only want to describe if user getting error in php using nlp google:

    useApplicationDefaultCredentials();
    # Your Google Cloud Platform project ID
    $projectId = 'nlp-project-nname'; //your project name
    
    # Instantiates a client
    $language = new LanguageClient([
        'projectId' => $projectId
    ]);
    
    # The text to analyze
    $text = 'Sachin Tendulkar';
    
    
    
    # Detects the sentiment of the text
    $annotation = $language->analyzeSentiment($text);
    $sentiment = $annotation->sentiment();
    echo "
    ";
    print_r($annotation); die;
    
    echo 'Text: ' . $text . '
    Sentiment: ' . $sentiment['score'] . ', ' . $sentiment['magnitude'];
    ?>
    

提交回复
热议问题