找不到com.google.appengine.api.urlfetch包

时间:2015-04-16 11:46:50

标签: google-app-engine import gradle

我们正在尝试使用URL提取器来检索获取GAE API方法的响应,使用以下代码。据我所知,这段代码是正确的,但导入似乎有问题。我是否错过了gradle构建文件中的依赖项?在互联网上环顾四周,但无处可去。

import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;

import java.io.IOException;
import java.net.URL;
import java.util.List;

…

URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();

try {
  URL url = new URL("<URL we use is redacted>");
  HTTPResponse response = fetcher.fetch(url);

  byte[] content = response.getContent();
  // if redirects are followed, this returns the final URL we are redirected to
  URL finalUrl = response.getFinalUrl();

  // 200, 404, 500, etc
  int responseCode = response.getResponseCode();
  List < HTTPHeader > headers = response.getHeaders();

  for (HTTPHeader header: headers) {
    String headerName = header.getName();
    String headerValue = header.getValue();
    System.out.println(headerName + " " + headerValue);
  }



} catch (IOException e) {
  // new URL throws MalformedUrlException, which is impossible for us here
}

我们收到以下错误:

/Users/Michael/Documents/GradeMe/app/src/main/java/com/ip/grademe/Register.java
Error:(12, 41) error: package com.google.appengine.api.urlfetch does not exist
Error:(13, 41) error: package com.google.appengine.api.urlfetch does not exist
Error:(14, 41) error: package com.google.appengine.api.urlfetch does not exist
Error:(15, 41) error: package com.google.appengine.api.urlfetch does not exist
Error:(73, 17) error: cannot find symbol class URLFetchService
Error:(73, 43) error: cannot find symbol variable URLFetchServiceFactory
Error:(77, 21) error: cannot find symbol class HTTPResponse
Error:(85, 26) error: cannot find symbol class HTTPHeader
Error:(87, 25) error: cannot find symbol class HTTPHeader

编辑:gradle.build文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.ip.grademe"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile project(path: ':backend', configuration: 'android-endpoints')
}

0 个答案:

没有答案