1

I'm trying to add some YouTube OAuth2.0 authorization for an Android project I'm working on using Android Studio. I got some sample code from here http://bit.ly/1SI805S. I'm pretty sure I linked to it from a Google developers site. I'm trying to add some libraries to take care of the dependencies but it isn't recognizing them. Here are the dependencies:

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.oauth2.Oauth2;
import com.google.api.services.oauth2.model.Tokeninfo;
import com.google.api.services.oauth2.model.Userinfoplus;

I downloaded a .jar for the com.google.api.services dependencies and that is working fine. I found the file on the Google developers site and it's google-api-services-oauth2-v2-rev103-1.21.0.jar. However, all of the api.client jars I've found are not working. I put them in the libs folder and add compile files to the build.gradle but it won't recognize the imports. The jars I've used thus far are google-api-client-util-1.2.3-alpha.jar google-api-client-extensions-1.6.0-beta.jar google-api-client-auth-1.2.3-alpha.jar Is there anything I'm missing? I've found these files in different parts of the net. I've looked through maven repositories and I just found a site, http://www.java2s.com/Code/Jar/g/Downloadgoogleapiclientutil121alphajar.htm, but I don't know that it's helpful. There's some api.client stuff I downloaded from the Google Developers site but that doesn't look like anything I need and it doesn't resolve the dependencies.

Spitz
  • 63
  • 1
  • 9

1 Answers1

2

Please follow the third apprach in my link, since your library is available online (remotely) as you see in the picture below. Android studio will recognize your dependencies if you add them in their standard ways. In general, there are three standard ways. Please read this link https://stackoverflow.com/a/35369267/5475941. In this post I explained how to import your JAR files in Android studio and I explained all possible ways step by step with screenshots. I hope it helps.

Search Result

Also, check your build.gradle (Moducle: app) and make sure your remote libraries are compatible with your current SDK. For example my SDK is 23.1.0:

My gradle.build

Google HTTP Client Library for Java. Functionality that works on all supported Java platforms, including Java 5 (or higher) desktop (SE) and web (EE), Android, and Google App Engine. https://github.com/google/google-http-java-client

Project metadata download:http://repo1.maven.org/maven2/com/google/http-client/google-http-client/1.16.0-rc/google-http-client-1.16.0-rc.pom

Binary download:http://repo1.maven.org/maven2/com/google/http-client/google-http-client/1.16.0-rc/google-http-client-1.16.0-rc.jar

Source download: http://repo1.maven.org/maven2/com/google/http-client/google-http-client/1.16.0-rc/google-http-client-1.16.0-rc-sources.jar

The classes that you are searching for are here:

enter image description here enter image description here

Community
  • 1
  • 1
Mohammad
  • 6,024
  • 3
  • 22
  • 30
  • I followed the steps with both the util and auth files but it's still not resolving the dependencies. – Spitz Feb 20 '16 at 22:51
  • I think I might be using the wrong files but I don't know where else I could get those files. – Spitz Feb 20 '16 at 22:52
  • buddy try the third approach. We call it remote libraries. Basically, Android studio uses https://bintray.com/. So, there you can find the right library. – Mohammad Feb 20 '16 at 23:00
  • I'm finding the files I need and for some reason the client.http and client.json dependencies were resolved without me adding anything for those but the ones for the files I added weren't resolved. I did a clean thinking that might but it's still not doing anything. – Spitz Feb 20 '16 at 23:15
  • buddy, make sure that your remote libraries are ended with your current SDK. For example, if your SDK is 23.1.0 and you see there 22.0.2, you should change it.I updated the answer for you. Please take another look at it. – Mohammad Feb 20 '16 at 23:29
  • Bintray worked for a couple of the dependencies. `google.api.client-1.21.0` took care client.googleapis but `client.extensions`, `client.auth`, `client.json`, and `client.util` still aren't resolving. I've added a few jars as libraries, `google-api-client-auth-oauth2-1.2.0-alpha.jar`, `google-api-client-util-1.2.3-alpha.jar`, `google-client-api-1.0.4.jar` and a few others. – Spitz Feb 21 '16 at 01:54
  • I updated the answer. Please use the source download link. – Mohammad Feb 21 '16 at 02:58