Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 关于谷歌+;域api。。。。。。。。。。。。使用已安装的应用程序列出圆圈时,禁止获取错误403_Java_Json_Api - Fatal编程技术网

Java 关于谷歌+;域api。。。。。。。。。。。。使用已安装的应用程序列出圆圈时,禁止获取错误403

Java 关于谷歌+;域api。。。。。。。。。。。。使用已安装的应用程序列出圆圈时,禁止获取错误403,java,json,api,Java,Json,Api,我刚刚在我的google+域api中列出了圆圈名称,但得到了一个错误 我在google开发者控制台中创建应用程序时使用了installed application->other选项 我正在开发一个小型已安装应用程序,其中我正在与Google+域API集成。我正在使用OAuth2身份验证。我已经从Google API控制台为我安装的应用程序生成了客户端id和客户端机密。使用Google+域API,我能够生成访问令牌 此外,我正在使用----some-----@gmail.com使用gmail帐户

我刚刚在我的google+域api中列出了圆圈名称,但得到了一个错误

我在google开发者控制台中创建应用程序时使用了installed application->other选项

我正在开发一个小型已安装应用程序,其中我正在与Google+域API集成。我正在使用OAuth2身份验证。我已经从Google API控制台为我安装的应用程序生成了客户端id和客户端机密。使用Google+域API,我能够生成访问令牌

此外,我正在使用----some-----@gmail.com使用gmail帐户

我的代码如下:-

enter code here


private static final String CLIENT_ID = "xyxxxxxxxx something in there";
private static final String CLIENT_SECRET = "Fhh1LYQ__UTso48snXHyqSQ2";


public static void main(String[] args) throws IOException {

// List the scopes your app requires:
try{
List<String> SCOPE = Arrays.asList(
    "https://www.googleapis.com/auth/plus.me",
    "https://www.googleapis.com/auth/plus.stream.write",
    "https://www.googleapis.com/auth/plus.circles.read");

final String REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob";


GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        new NetHttpTransport(),
        new JacksonFactory(),
        CLIENT_ID, // This comes from your Developers Console project
        CLIENT_SECRET, // This, as well
        SCOPE)
        .setApprovalPrompt("force")
        // Set the access type to offline so that the token can be refreshed.
        // By default, the library will automatically refresh tokens when it
        // can, but this can be turned off by setting
        // dfp.api.refreshOAuth2Token=false in your ads.properties file.
        .setAccessType("offline").build();

                       // This command-line se`enter code here`rver-side flow example requires the                user             to open the
    // authentication URL in their browser to complete the process. In most
    // cases, your app will use a browser-based server-side flow and your
    // user will not need to copy and paste the authorization code. In this
    // type of app, you would be able to skip the next 5 lines.
    // You can also look at the client-side and one-time-code flows for other
    // options at https://developers.google.com/+/web/signin/
    String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
    System.out.println("Please open the following URL in your browser then " +
        "type the authorization code:");
    System.out.println("  " + url);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();
    // End of command line prompt for the authorization code.

    GoogleTokenResponse tokenResponse = flow.newTokenRequest(code)
        .setRedirectUri(REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(new NetHttpTransport())
        .setJsonFactory(new JacksonFactory())
        .setClientSecrets(CLIENT_ID, CLIENT_SECRET)
        .addRefreshListener(new CredentialRefreshListener() {
          @Override
          public void onTokenResponse(Credential credential, TokenResponse tokenResponse) {
            // Handle success.
            System.out.println("Credential was refreshed successfully.");
          }

          @Override
          public void onTokenErrorResponse(Credential credential,
              TokenErrorResponse tokenErrorResponse) {
            // Handle error.
            System.err.println("Credential was not refreshed successfully. "
                + "Redirect to error page or login screen.");
          }
        })
        // You can also add a credential store listener to have credentials
        // stored automatically.
        //.addRefreshListener(new CredentialStoreRefreshListener(userId, credentialStore))
        .build();

    // Set authorized credentials.
    credential.setFromTokenResponse(tokenResponse);
    // Though not necessary when first created, you can manually refresh the
    // token, which is needed after 60 minutes.
    credential.refreshToken();

    // Create a new authorized API client
    PlusDomains service = new PlusDomains.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName("Get-me").setRootUrl("https://www.googleapis.com/").build();


    PlusDomains.Circles.List listCircles = service.circles().list("me");
    listCircles.setMaxResults(5L);
    CircleFeed circleFeed = listCircles.execute();
    List<Circle> circles = circleFeed.getItems();

    // Loop until no additional pages of results are available.
    while (circles != null) {
      for (Circle circle : circles) {
        System.out.println(circle.getDisplayName());
      }

      // When the next page token is null, there are no additional pages of
      // results. If this is the case, break.
      if (circleFeed.getNextPageToken() != null) {
        // Prepare the next page of results
        listCircles.setPageToken(circleFeed.getNextPageToken());

        // Execute and process the next page request
        circleFeed = listCircles.execute();
        circles = circleFeed.getItems();
      } else {
        circles = null;
      }
    }
             }catch(Exception e)
          {
           System.out.println("Exception  "+e);
           }

           }
在此处输入代码
private static final String CLIENT_ID=“xyxxxxxxxx某物在那里”;
私有静态最终字符串客户端\u SECRET=“fh1lyq\uuu UTso48snXHyqSQ2”;
公共静态void main(字符串[]args)引发IOException{
//列出应用程序需要的范围:
试一试{
列表范围=Arrays.asList(
"https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/plus.stream.write",
"https://www.googleapis.com/auth/plus.circles.read");
最终字符串重定向_URI=“urn:ietf:wg:oauth:2.0:oob”;
GoogleAuthorizationCodeFlow=新建GoogleAuthorizationCodeFlow.Builder(
新的NetHttpTransport(),
新JacksonFactory(),
CLIENT\u ID,//这来自开发人员控制台项目
CLIENT\u SECRET,//这个也是
范围)
.setApprovalPrompt(“强制”)
//将访问类型设置为脱机,以便可以刷新令牌。
//默认情况下,库在启动时将自动刷新令牌
//可以,但可以通过设置
//ads.properties文件中的dfp.api.refreshOAuth2Token=false。
.setAccessType(“脱机”).build();
//此命令行se`enter code here`Server端流示例要求用户打开
//在浏览器中完成验证URL的过程。在大多数情况下
//在某些情况下,您的应用程序将使用基于浏览器的服务器端流和
//用户将不需要复制和粘贴授权代码。在此
//应用程序类型,您可以跳过接下来的5行。
//您还可以查看客户端和其他客户端的一次性代码流
//期权在https://developers.google.com/+/网页/登录/
字符串url=flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI.build();
System.out.println(“请在浏览器中打开以下URL”+
“键入授权代码:”;
System.out.println(“+url”);
BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in));
字符串代码=br.readLine();
//输入授权代码的命令行提示符结束。
GoogleTokenResponse tokenResponse=flow.newTokenRequest(代码)
.setRedirectUri(REDIRECT_URI).execute();
GoogleCredential credential=新建GoogleCredential.Builder()
.setTransport(新的NetHttpTransport())
.setJsonFactory(新JacksonFactory())
.setClientSecrets(客户端ID、客户端机密)
.addRefreshListener(新证书RefreshListener(){
@凌驾
公共无效onTokenResponse(凭据凭据、令牌响应、令牌响应){
//处理成功。
System.out.println(“凭证已成功刷新”);
}
@凌驾
public void onTokenErrorResponse(凭证凭证,
令牌错误响应(令牌错误响应){
//处理错误。
System.err.println(“凭证未成功刷新。”
+“重定向到错误页面或登录屏幕。”);
}
})
//您还可以添加凭据存储侦听器以具有凭据
//自动存储。
//.addRefreshListener(新凭据存储RefreshListener(用户ID,凭据存储))
.build();
//设置授权凭据。
credential.setFromTokenResponse(tokenResponse);
//虽然首次创建时不需要,但可以手动刷新
//60分钟后需要的令牌。
credential.refreshtToken();
//创建新的授权API客户端
PlusDomains服务=新的PlusDomains.Builder(新的NetHttpTransport(),新的JacksonFactory(),凭证)。setApplicationName(“Get me”)。setRootUrl(“https://www.googleapis.com/build();
PlusDomains.Circles.List listCircles=service.Circles().List(“我”);
listCircles.setMaxResults(5L);
CircleFeed CircleFeed=listCircles.execute();
列表圈=circleFeed.getItems();
//循环,直到没有其他页面的结果可用。
while(圆圈!=null){
用于(圆:圆){
System.out.println(circle.getDisplayName());
}
//当下一页标记为null时,将不会有其他页
//结果。如果是这种情况,请中断。
if(circleFeed.getNextPageToken()!=null){
//准备下一页的结果
setPageToken(circleFeed.getNextPageToken());
//执行并处理下一页请求
circleFeed=listCircles.execute();
circles=circleFeed.getItems();
}否则{
圆圈=空;
}
}
}捕获(例外e)
{
系统输出打印项次(“例外”+e);
}
}
它是一个已安装的应用程序->其他选项。。。。。。。。在谷歌开发者控制台

我得到以下错误:---

异常com.google.api.client.googleapis.json.googlejson响应异常:403禁止 { “代码”:403, “错误”:[{ “域”:“全局”, “消息”:“禁止”, “原因”:“禁止” } ], “消息”:“禁止” }

注意:我还在我的Google API控制台中启用了Google+域API

重定向_URI=“urn:ietf:wg:oauth:2.0:oob”s