所以我按照本教程制作了一个基本的Picasawebalbums Api应用程序。我在这里得到了教程https://developers.google.com/picasa-web/docs/2.0/developers_guide_java
我在此处描述的问题Create PicasawebService和此处Error while using PicasawebService with GAE以及此处upload image to Picasa using picasawebservice in android
我解决了classNotFoundException,现在有了authenticationException。我发现了一些有关这方面的问题,但没有一个有帮助。
堆栈跟踪
Exception in thread "main" com.google.gdata.util.AuthenticationException: Error authenticating (check service name)
at com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFactory.java:688)
at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:560)
at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:397)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:364)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:319)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:303)
at duh.Test.main(Test.java:37)
这是我的代码
public static void main(String args[]) throws IOException, ServiceException, AuthenticationException{
PicasawebService myService = new PicasawebService(APP_NAME);
myService.setConnectTimeout(60000);
myService.setReadTimeout(60000);
myService.setUserCredentials(EMAIL, PASSWORD);
URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/samdup123?kind=album");
UserFeed myUserFeed = myService.getFeed(feedUrl, UserFeed.class);
for(AlbumEntry myAlbum : myUserFeed.getAlbumEntries()){
System.out.println(myAlbum.getTitle().getPlainText());
}
}
}
我的进口
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import com.google.gdata.client.*;
import com.google.gdata.client.photos.*;
import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.*;
import com.google.gdata.data.media.*;
import com.google.gdata.data.photos.*;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
第37行从堆栈跟踪指向myService.setUserCredentials(EMAIL, PASSWORD);
似乎我需要完全删除此代码并使用OAuth2进行身份验证。我已经读过这篇文章,但阅读非常复杂,我不知道该怎么用于我的应用程序。我找到了这段代码
SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
File p12 = new File("D:\\cgi\\RemedyClientTest\\src\\main\\resources\\RemedyClient-b04b4c2d956c.p12");
factory = FeedURLFactory.getDefault();
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String [] SCOPESArray= {"https://spreadsheets.google.com/feeds", "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds"};
final List SCOPES = Arrays.asList(SCOPESArray);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("1088335521358-ijasu5h7kauqbja6hih91l2c23amv7ft@developer.gserviceaccount.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(p12)
.build();
service = new SpreadsheetService("Main");
service.setOAuth2Credentials(credential);
但我不知道如何将其“翻译”为PicasawebAlbums。我已经尝试过,但是因为我不知道要导入什么jar文件。
我是否正确地认为我的问题是我需要使用Oauth2?还有什么我应该用的吗?如果有人有一个有效的应用程序,你可以告诉我你所有的进口产品,因为我的一些产品似乎已经过时并被其他产品取代而且非常令人困惑。