[請益] PHP GET中有符號+

看板PHP作者 (萬)時間14年前 (2011/11/11 17:32), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串1/1
大家好: 我在使用google api OAuth2 使用了網路上寫好的callback.php http://ppt.cc/qJmC $url = "https://accounts.google.com/o/oauth2/auth?". http_build_query(array( 'client_id' => $client_id, 'redirect_uri' => $redirect_uri, 'scope' => $scope, 'response_type' => 'code' )); 其中GET欄位中有個scope http://ppt.cc/k-zE 如果想要帳號資料和email資料 需要在scope中加入 https://www.googleapis.com/auth/userinfo.profile+ https://www.googleapis.com/auth/userinfo.email 在callback.php中有$scope變數來存 結果連結變成 https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%2B https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email 導致OAuth 2.0 錯誤:invalid_scope 在網址列上手動改成+就沒問題 請問這要怎麼改呢?? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.189.82 找到一個笨方法 把GET參數手動加 $url = "https://accounts.google.com/o/oauth2/auth?scope=".$scope."&". http_build_query(array( 'client_id' => $client_id, 'redirect_uri' => $redirect_uri, 'response_type' => 'code' )); ※ 編輯: onininon 來自: 220.133.189.82 (11/11 17:46)

11/11 18:14, , 1F
urldecode
11/11 18:14, 1F

11/11 21:12, , 2F
我猜urlencode 問題http送進get 參數請先 urlencode
11/11 21:12, 2F
謝謝解答 $url = "https://accounts.google.com/o/oauth2/auth?". http_build_query(array( 'client_id' => $client_id, 'redirect_uri' => $redirect_uri, 'scope' => urldecode($scope), 'response_type' => 'code' )); 改成這樣就沒問題了! ※ 編輯: onininon 來自: 220.133.189.82 (11/14 11:27)
文章代碼(AID): #1ElEl1Kl (PHP)
文章代碼(AID): #1ElEl1Kl (PHP)