我想從這個社交媒體獲取資料:https : //vk.com/dev/authcode_flow_user 我寫了一些代碼,但出現錯誤:(401 Unauthorized: "{"error":"invalid_client","error_description":"client_id是不正確的”}”)。它發生在指南的第一步。但是我發誓我正確地撰寫了 client_id 引數,當我嘗試在 Postman 和瀏覽器中發送請求時它可以作業。拜托,有人能告訴我有什么問題嗎?
這是我在 Spring 應用程式中的代碼:
@SpringBootApplication
public static void main(String[] args) {
SpringApplication.run(BlogApplication.class, args);
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("client_id", "<here my id, I dont want to show it>");
uriVariables.put("display", "page");
uriVariables.put("redirect_uri", "http://vk.com");
uriVariables.put("scope", "friends");
uriVariables.put("response_type", "code");
uriVariables.put("v", "5.131");
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
final HttpEntity<String> entity = new HttpEntity<String>(headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Map> response = restTemplate.exchange("https://oauth.vk.com/authorize?", HttpMethod.GET, entity, Map.class, uriVariables);
System.out.println(response.getBody());
uj5u.com熱心網友回復:
它不起作用的原因是因為這不是您希望獲得單個回應的 REST 端點。
您發出的這個呼叫會授權用戶,然后重定向到您在第一個 URL 中提供的另一個 URI。
如果用戶在當前瀏覽器中沒有在 VK 中獲得授權,他們將被要求在對話視窗中輸入登錄名和密碼。
可能在瀏覽器中,您已經使用身份驗證視窗對自己進行了一次授權,之后它繼續作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/400960.html
上一篇:如何更新兩個單獨串列中的字典?
