package com.login.client;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
public class FetchUrl {
private static String client_id = "<Client ID>";
private static String client_secret = "<client_secret>";
private static String redirectURL = "http://gfksgnbgfcv.appspot.com/index2.jsp";
private static URLFetchService fetchService;
public static String getParseValue(String code){
HTTPResponse httpResponse=null;
try {
String urlStr="https://accounts.google.com/o/oauth2/token";
URL url = new URL(urlStr);
HTTPMethod method=HTTPMethod.POST;
HTTPRequest httpRequest = new HTTPRequest(url,method);
fetchService = URLFetchServiceFactory.getURLFetchService();
httpRequest.setHeader(new HTTPHeader("Content-Type", "application/x-www-form-urlencoded"));
httpRequest.setHeader(new HTTPHeader("Content-length", "250"));
httpRequest.addHeader(new HTTPHeader("code", code));
httpRequest.addHeader(new HTTPHeader("client_id", client_id));
httpRequest.addHeader(new HTTPHeader("client_secret", client_secret));
httpRequest.addHeader(new HTTPHeader("redirect_uri", redirectURL));
httpRequest.addHeader(new HTTPHeader("scope", ""));
httpRequest.addHeader(new HTTPHeader("grant_type", "authorization_code"));
httpResponse = fetchService.fetch(httpRequest);
InputStream in=getContentAsStream(httpResponse);
BufferedReader reader = new BufferedReader( new InputStreamReader(in));
String line;
String output="";
while ((line = reader.readLine()) != null) {
output=output+line;
}
reader.close();
return output;
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
return e.getMessage();
}
}
public static byte[] getContentAsBytes(HTTPResponse httpResponse) {
return httpResponse.getContent();
}
public static InputStream getContentAsStream(HTTPResponse httpResponse) {
return new ByteArrayInputStream(getContentAsBytes(httpResponse));
}
}
相关推荐
Google App Engine 是一种让您可以在 Google 的基础架构上运行您的网络应用程序。Google App Engine 应用程序易于构建和维护,并可根据您的访问量和数据存储需要的增长轻松扩展。使用 Google App Engine,将不再需要...
Google App Engine 是一种让您可以在 Google 的基础架构上运行您的网络应用程序。Google App Engine 应用程序易于构建和维护,并可根据您的访问量和数据存储需要的增长轻松扩展。使用 Google App Engine,将不再需要...
Readers will learn how to implement a token-based authentication and access control for an isomorphic application. Chapter 9, Testing and Deploying Your App, explains how to configure unit and ...
Brightpearl API Python客户端 包装请求库以与Brightpearl API进行...api.oauth_fetch_token(code= " XYZ " , access_redirect_url= " http://localhost/access_redirect_url " ) # To refresh token api.refresh_token
主要介绍了javascript实现fetch请求返回的统一拦截,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
The final section in this chapter shows us how to create highly optimized URLs for our user profiles, and how to build custom Route classes to obtain even more flexibility. Chapter 7, Creating and ...
一个基于 Fetch API 封装的 HTTP Client,可用于浏览器及其他兼容环境中,设计之初是为了ReactJS和React... request.options.headers['X-Access-Token'] = token; return request; }); }); 标签:Fetch
在Ubuntu上搭建以太坊环境时,每次到sudo apt-get install ethereum这一步都会变得巨卡无比,并且经常遇到这个问题: ... Connection timed out...E: Failed to fetch http://ppa.launchpad.net/ethereum/ethereum/ubuntu
This book is designed to teach you how to use AdonisJs. To get the most out of it, you should have a firm grasp of modern JavaScript and some knowledge of how to work with relational databases and the...
how-to-use-fetch-api:此源代码展示了如何使用fetch API
//Automatically passes the current location in order to processes the access token, instance URL, etc.sf . query ( "SELECT Id, Name FROM Contact" ) . then ( records => { //Do something with the ...
This example shows how you can use OleDbSchemaGuid in ADO.NET to fetch Schema information from database. It also shows, how you can use DataGrid control, to fill records from dataset, and also how to ...
Unexpected token in JSON at position 0 眼熟的错误,可能以前当你发送一个HTTP请求的时候,都曾出现过这个错误提示或者相似的错误,那这个错误是由什么引起的呢 报错原因 这些错误发生在你向服务器发送请求的时候...
Chapter 19: Data Binding shows you how to fetch information from a database, insert it into a custom data objects, and bind these objects to WPF controls. You’ll also learn how to improve the ...
* How to Install AdminLTE 3 (Template used for admin panel) * How to Use Font Awesome 5 on Laravel (Used for admin panel icon) * Vform validation with Laravel (Used for form validation) * ...
$getuserid = $_SGLOBAL['db']->fetch_array($querygetuser); if ($getuserid['emailcheck'] == 0 && $_SGLOBAL['db']->num_rows($querygetuser) != 0) { showmessage('email_unchecked', 'do.php?ac='.$_SCONFIG...
利用zabbix监控mysql,方便好用,不需要在被监控端安装或执行任何脚本
本文主要介绍解决安装使用SDK Manager更新时的问题:Failed to fetch URL...,这里提供了详细的资料及解决问题办法,有需要的小伙伴可以参考下
nessus2023-04-10漏洞更新包all-2.0.tar.gz以把插件包上传到服务器后, 执行/opt/nessus/sbin/nessuscli update 插件包文件路径 Linux/Unix /opt/nessus/sbin/nessuscli fetch --register-offline nessus.license ...
go-fetch-oauth1 OAuth v1 身份验证。 安装 npm install --save go-fetch go-fetch-oauth1 用法 var Client = require('go-fetch'); var OAuth1 = require('go-fetch-oauth1'); var prefixUrl = require('go-...