尝试执行twilio Java api失败如下:
18:17:35.270 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: best-match
18:17:35.296 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
18:17:35.297 [main] DEBUG o.a.h.impl.client.DefaultHttpClient - Reopening the direct connection.
18:17:35.297 [main] DEBUG o.a.h.impl.client.DefaultHttpClient - Attempt 1 to execute request
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:197)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:410)
at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:581)
at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
at ws.SmsSender.main(SmsSender.java:34)
Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:98)
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:37)
... 16 more
18:17:35.334 [main] DEBUG o.a.h.impl.client.DefaultHttpClient - Closing the connection.
我认为这与Maven中的依赖问题有关。这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wat</groupId>
<artifactId>ws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ws</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>foursquareapijava</id>
<name>Foursquare V2 API for Java Repository</name>
<url>http://foursquare-api-java.googlecode.com/svn/repository</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-auth</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>6.1</version>
</dependency>
<dependency>
<groupId>net.vz.mongodb.jackson</groupId>
<artifactId>mongo-jackson-mapper</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio-java-sdk</artifactId>
<version>3.4.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.12.0-rc2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>fi.foyt</groupId>
<artifactId>foursquare-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.1.0</version>
</dependency>
<!-- <dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-integration</artifactId>
<version>0.9</version>
</dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>ws.WSService</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这里是mvn依赖的输出:tree -Dverbose
Last login: Tue Jun 24 18:09:15 on ttys002
$ mvn dependency:tree -Dverbose
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ws 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ ws ---
[INFO] com.wat:ws:jar:0.0.1-SNAPSHOT
[INFO] +- com.yammer.dropwizard:dropwizard-core:jar:0.6.2:compile
[INFO] | +- com.sun.jersey:jersey-core:jar:1.17.1:compile
[INFO] | +- com.sun.jersey:jersey-server:jar:1.17.1:compile
[INFO] | | +- asm:asm:jar:3.1:compile
[INFO] | | \- (com.sun.jersey:jersey-core:jar:1.17.1:compile - omitted for duplicate)
[INFO] | +- com.sun.jersey:jersey-servlet:jar:1.17.1:compile
[INFO] | | \- (com.sun.jersey:jersey-server:jar:1.17.1:compile - omitted for duplicate)
[INFO] | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.2:compile - omitted for conflict with 1.7.4)
[INFO] | +- com.yammer.metrics:metrics-servlet:jar:2.2.0:compile
[INFO] | | +- (com.yammer.metrics:metrics-core:jar:2.2.0:compile - omitted for duplicate)
[INFO] | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.1.1:compile - omitted for conflict with 2.1.4)
[INFO] | +- com.yammer.metrics:metrics-jetty:jar:2.2.0:compile
[INFO] | | +- (com.yammer.metrics:metrics-core:jar:2.2.0:compile - omitted for duplicate)
[INFO] | | \- (org.eclipse.jetty:jetty-server:jar:8.1.8.v20121106:compile - omitted for conflict with 8.1.10.v20130312)
[INFO] | +- com.yammer.metrics:metrics-logback:jar:2.2.0:compile
[INFO] | | +- (com.yammer.metrics:metrics-core:jar:2.2.0:compile - omitted for duplicate)
[INFO] | | +- (ch.qos.logback:logback-core:jar:1.0.7:compile - omitted for conflict with 1.0.10)
[INFO] | | \- (ch.qos.logback:logback-classic:jar:1.0.7:compile - omitted for conflict with 1.0.10)
[INFO] | +- com.yammer.metrics:metrics-jersey:jar:2.2.0:compile
[INFO] | | +- (com.yammer.metrics:metrics-core:jar:2.2.0:compile - omitted for duplicate)
[INFO] | | +- com.yammer.metrics:metrics-annotation:jar:2.2.0:compile
[INFO] | | \- (com.sun.jersey:jersey-server:jar:1.15:compile - omitted for conflict with 1.17.1)
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.1.4:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.1.4:compile
[INFO] | | \- (com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile - omitted for conflict with 2.1.1)
[INFO] | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.1.4:compile
[INFO] | | +- (com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile - omitted for duplicate)
[INFO] | | +- (com.fasterxml.jackson.core:jackson-databind:jar:2.1.4:compile - omitted for duplicate)
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.1.4:compile
[INFO] | | +- (com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile - omitted for duplicate)
[INFO] | | \- (com.fasterxml.jackson.core:jackson-databind:jar:2.1.4:compile - omitted for duplicate)
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.1.4:compile
[INFO] | | \- (com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile - omitted for duplicate)
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.1.2:compile
[INFO] | | +- (com.fasterxml.jackson.core:jackson-databind:jar:2.1.2:compile - omitted for conflict with 2.1.4)
[INFO] | | +- (com.fasterxml.jackson.core:jackson-core:jar:2.1.2:compile - omitted for conflict with 2.1.4)
[INFO] | | \- (com.google.guava:guava:jar:11.0.2:compile - omitted for conflict with 14.0.1)
[INFO] | +- net.sourceforge.argparse4j:argparse4j:jar:0.4.0:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.4:compile
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.4:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.4:compile - omitted for duplicate)
[INFO] | +- ch.qos.logback:logback-core:jar:1.0.10:compile
[INFO] | +- ch.qos.logback:logback-classic:jar:1.0.10:compile
[INFO] | | +- (ch.qos.logback:logback-core:jar:1.0.10:compile - omitted for duplicate)
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.2:compile - omitted for conflict with 1.7.4)
[INFO] | +- org.slf4j:log4j-over-slf4j:jar:1.7.4:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.4:compile - omitted for duplicate)
[INFO] | +- org.eclipse.jetty:jetty-server:jar:8.1.10.v20130312:compile
[INFO] | | +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
[INFO] | | +- org.eclipse.jetty:jetty-continuation:jar:8.1.10.v20130312:compile
[INFO] | | \- (org.eclipse.jetty:jetty-http:jar:8.1.10.v20130312:compile - omitted for duplicate)
[INFO] | +- org.eclipse.jetty:jetty-servlet:jar:8.1.10.v20130312:compile
[INFO] | | \- org.eclipse.jetty:jetty-security:jar:8.1.10.v20130312:compile
[INFO] | | \- (org.eclipse.jetty:jetty-server:jar:8.1.10.v20130312:compile - omitted for duplicate)
[INFO] | +- org.eclipse.jetty:jetty-http:jar:8.1.10.v20130312:compile
[INFO] | | \- org.eclipse.jetty:jetty-io:jar:8.1.10.v20130312:compile
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:8.1.10.v20130312:compile
[INFO] | +- com.google.guava:guava:jar:14.0.1:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:4.3.1.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] | | \- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] | +- joda-time:joda-time:jar:2.2:compile
[INFO] | \- (com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.1.2:compile - omitted for conflict with 2.1.1)
[INFO] +- com.yammer.dropwizard:dropwizard-auth:jar:0.6.2:compile
[INFO] | \- (com.yammer.dropwizard:dropwizard-core:jar:0.6.2:compile - omitted for duplicate)
[INFO] +- com.googlecode.libphonenumber:libphonenumber:jar:6.1:compile
[INFO] +- net.vz.mongodb.jackson:mongo-jackson-mapper:jar:1.4.2:compile
[INFO] | +- (org.mongodb:mongo-java-driver:jar:2.7.2:compile - omitted for conflict with 2.12.0-rc2)
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.3:compile (version managed from 1.9.5)
[INFO] | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.3:compile
[INFO] | +- de.undercouch:bson4jackson:jar:1.3.0:compile
[INFO] | | +- (org.codehaus.jackson:jackson-core-asl:jar:1.7.4:compile - omitted for conflict with 1.9.3)
[INFO] | | \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.9.3:compile - version managed from 1.7.4; omitted for duplicate)
[INFO] | \- javax.persistence:persistence-api:jar:1.0.2:compile
[INFO] +- com.twilio.sdk:twilio-java-sdk:jar:3.4.5:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
[INFO] | | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | \- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] | \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.9.3:compile - version managed from 1.7.4; omitted for duplicate)
[INFO] +- org.mongodb:mongo-java-driver:jar:2.12.0-rc2:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.1.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.1.1:compile
[INFO] | +- (com.fasterxml.jackson.core:jackson-databind:jar:2.1.1:compile - omitted for conflict with 2.1.4)
[INFO] | \- (joda-time:joda-time:jar:2.1:compile - omitted for conflict with 2.2)
[INFO] +- fi.foyt:foursquare-api:jar:1.0.2:compile
[INFO] | +- org.json:json:jar:20090211:compile
[INFO] | \- com.google.appengine:appengine-api-1.0-sdk:jar:1.6.5:compile
[INFO] \- org.scribe:scribe:jar:1.1.0:compile
[INFO] \- commons-codec:commons-codec:jar:1.4:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.901 s
[INFO] Finished at: 2014-06-24T18:41:27-08:00
[INFO] Final Memory: 12M/183M
[INFO] ------------------------------------------------------------------------
$
正在执行的代码:
package ws;
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.TwilioRestResponse;
import com.twilio.sdk.resource.factory.CallFactory;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.*;
import com.twilio.sdk.resource.list.AccountList;
import com.twilio.sdk.resource.list.AvailablePhoneNumberList;
import com.twilio.sdk.resource.list.ParticipantList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import java.util.*;
public class SmsSender {
// Find your Account Sid and Token at twilio.com/user/account
public static final String ACCOUNT_SID = "<HIDDEN>";
public static final String AUTH_TOKEN = "<HIDDEN>";
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
Account mainAccount = client.getAccount();
// Send an sms (using the new messages endpoint)
MessageFactory messageFactory = mainAccount.getMessageFactory();
List<NameValuePair> messageParams = new ArrayList<NameValuePair>();
messageParams.add(new BasicNameValuePair("To", "+HIDDEN")); // Replace with a valid phone number
messageParams.add(new BasicNameValuePair("From", "+HIDDEN")); // Replace with a valid phone
// number in your account
messageParams.add(new BasicNameValuePair("Body", "This is a test message!"));
messageFactory.create(messageParams);
}
}
有什么想法吗?
答案 0 :(得分:3)
来自twilio:
嗨马修,
感谢您与我们联系。
看起来像&#34; foursquare-api&#34;正在引进 &#34;应用服务引擎的API-1.0-SDK&#34;依赖性。
[INFO] +- fi.foyt:foursquare-api:jar:1.0.2:compile [INFO] | +- org.json:json:jar:20090211:compile [INFO] | \- com.google.appengine:appengine-api-1.0-sdk:jar:1.6.5:compile
您可以尝试排除此依赖关系,但我希望它会 可能会破坏&#34; foursquare-api&#34;库。
&#34; twilio-java的&#34;对此没有对App Engine的硬性依赖 原因。
如果您有任何其他问题,请告诉我们。
Alex Chan Twilio客户支持www.twilio.com
更新了pom.xml,如下所示:
<dependency>
<groupId>fi.foyt</groupId>
<artifactId>foursquare-api</artifactId>
<version>1.0.2</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
</exclusion>
</exclusions>
</dependency>