I can create a file and give permissions with Driver API.
For Spreadsheet i use "Spreadsheet API".
The permission that i give is: "public for anyone - read only". The case is i can't read the Spreadsheet Cells. The only way that i can read is if i add "Publish to the Web" like say James Moore. Code example:
String urlString = "https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";
URL url = new URL(urlString);
ListFeed feed = service.getFeed(url, ListFeed.class); // Then feed.getEntries()
But if thats the case, how i can read a shared file or how i can set "Publish to the Web" a file via Java code?
First, Documents List API is depricated. Use Drive API instead. You can achieve the same goal by Files.insert().
Second, use spreadsheets api to read spreadsheet. You can also use Spreadsheet service of Google Apps Script. You don't have to publish to the web if you use either one of these two.
I found that for now is not possible. Maybe in a near future;
Spreadsheet API: https://developers.google.com/google-apps/spreadsheets/
Weeks ago Google put some lines that explain this:
The private visibility can be replaced with the public visibility, which enables the feed to work without authorization for spreadsheets that have been "Published to the Web". The public visibility is supported on the worksheets, list, and cells feeds. The public visibility is useful for accessing the contents of a spreadsheet from the client context of a web page in JavaScript, for example.
Publishing a spreadsheet to the web can only be done from the Google Spreadsheets user interface. To start publishing a spreadsheet to the web, select File > Publish to the web from the Spreadsheets user interface, and then click the Start Publishing button.
Warning: API requests using the public visiblity for feeds on spreadsheets that are not "Published to the Web" yield an HTTP 400 Bad Request response with the message The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn't deleted it.
Warning: The public visibility does not work for spreadsheets that are made "Public on the web" from the "Visibility options" portion of the sharing dialog of a Google Spreadsheet. "Published to the web" and "Public on the web" are different ways to share a spreadsheet. We are aware that this is confusing, and will address it in a future version of the API. For now, we hope that this detailed warning prevents confusion.
Related
I have the following URL https://api.vimeo.com/search?from=me&q=test but when i try access it tells me no user credentials where provided. i already made a token with all the fields including private and public and also the other spaces.So in this URL where and how should i add the token? I found in some documentation that said that this link https://vimeo.com/search?q=Mazda+2 will also work for api.vimeo.com/search?q....... what i want is to integrate in my android app depending on the selected it in a recyclerView do a query according to the name of the item to put it at the end of https://vimeo.com/search?q= (Name of the item) and then show the results in a Listview for the user to select which videos they could see.
And then play the video selected.
Your question is very general, vimeo uses OAuth 2.0, you have to decide what type of token you need for public or private content, depending on it your authentication workflow will change.
You should first study the authentication documentation of the vimeo api.
For example, user is navigating to google.com in WebView.
Is it possible to authorize him there via Google Account Picker (something like described here https://developers.google.com/android/guides/http-auth) to simplify authorization instead of manually logging in via web form?
Android Web browsers (for example, Google Chrome) are authorizing user via this method).
Part I: Using the Google Plus Services API
If I understand your question correctly, you may be able to achieve what you are trying to do using the Google Plus Services API.
You create your GoogleSignInOptions and then create your GoogleApiClient using these sign-in options. From there, you use the Auth.GoogleSignInApi.getSignInIntent with your GoogleApiClient as the parameter.
This intent should launch a SignInIntent that presents the Google account picker (that will include accounts that have been accessed on the device previously, and the ability to add another account).
Once you get back the GoogleSignInResult, you can verify that the user was authenticated and then create the authentication flow as you would otherwise.
Even included in the Android SDK is the Google SignInButton, which you can use right in your layout instead of having to create a custom button for the sign-in.
Part II: Using WebViewClient
Now, if you are trying to use a WebView to authenticate them, your best bet is to extend the WebViewClient class.
Things you will need: clientId, clientSecret, and clientScope (all of these details will be given for you when you create your application in the Google Developer Console)
First things first, your URL to authorize will probably be as follows: https://accounts.google.com/o/oauth2/auth?response_type=code&clientId={your client id}&state={SOMESTATEINFO}&access_type=offline (access type if you want offline access). This should be the initial URL of your WebView
Next, you will want to modify your extended WebViewClient class. What you will want to do is override the shouldOverrideUrlLoading(WebView webView, String url) method to listen for your redirectURL. Probably the easiest thing to do is to use url.startsWith(<your redirect URL>) to detect this. You can then parse the response. If your response contains error, then it means something went wrong. Otherwise, you should get back two fields in the URL: code and state. If you do not get error back, then return true for shouldOverrideUrlLoading.
Once you get your code, you can create a new GoogleAuthorizationCodeFlow, using your client, scopes, and secrets.
Once you have your flow, you will need a GoogleTokenResponse, which you will be able to get using the code obtained above for your authorization code, using GoogleTokenResponse response = flow.newTokenResponse(<code>).setRedirectUri(<redirectUri>).execute().
Once you have done this, and you have your response, you can get your Credential using flow.createAndStoreCredential(response, null).
And voila, using this Credential, you can authenticate your calls.
Caveats I have not been able to get the WebView to recognize accounts that have been signed into on other web browsers, so the account picker may only show the accounts that have been signed into on the app-specific WebView.
tl;dr It is possible to do this with a WebView and WebViewClient, but it's messy and a little bit more roundabout than using the Google Plus Services API.
This example better illustrates the authorization flow/credential stuff once you get the authorization code and such.
And here's some documentation on the WebViewClient that may be useful as well.
Hope this helps point you in the right direction!
I'm searching the PlayServices equivalent of this call:
https://www.googleapis.com/plus/v1/people/<some_user_id>?key=<your_api_key>
The call above is documentation of the call above is here: https://developers.google.com/+/web/api/rest/latest/people/get
However this is a web API call and my keys are restricted to a limited set of IPs. I think it would be a bad idea to put that key in code. Do you think the same?
Just as a side note I would like get the data without "authorization". I mean I authenticate with my key, but I don't want to ask the user. With the HTTP call above this is possible, so what is the Android SDK equivalent? I'm not asking how to do the GoogleApiClient stuff I have this already working. I just want to know the right call of the plus API.
If there is nothing similar do you know how to authenticate myself at the rest service with my packagename and signature?
In summary I just want to know the (first and last) name of the local G+ accounts like in the Google Foto app.
To load a specific Google+ profile in Android use the load method for com.google.android.gms.plus.People.
public abstract PendingResult<People.LoadPeopleResult> load (GoogleApiClient googleApiClient, String... personIds)
I'm trying to use the YouTubeData API with OAuth 2.0 authentication on Android, and i'm kind of struggling with it.
I've searched a lot online, but there's not much help for the Android implementation.
First of all, it's not clear to me what's the best way to obtain an OAuth token. In the doc they suggest that for Android is better to obtain it using the Google Play services lib. Is that true? if yes, it should be pretty trivial following this guide: https://developers.google.com/android/guides/http-auth.
But at this point i will have the token in a String object .. how should I use it with the YouTubeData API? Should I place it somewhere in the YouTube.Builder ?
YouTube youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}
}).setApplicationName("AppName").build();
if yes, does anyone know where?
Searching on StackOverflow i've come across this question: What to do after getting Auth Token - Android Youtube API. Here Ibrahim Ulukaya says it's better to use GoogleAccountCredential. For what i've understood (Access to Google API - GoogleAccountCredential.usingOAuth2 vs GoogleAuthUtil.getToken()) the Android version of GoogleAccountCredential should use the GoogleAuthUtil provided from the Google Play services lib, so it could be pretty useful to simplify the process. I've looked at the sample project suggested from Ibrahim Ulukaya (https://github.com/youtube/yt-direct-lite-android) and i've implemented everything as he does. But it doesn't seem to work very well as i'm only obtaining this message in the logcat: "There was an IO error: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission : null".
(Note that I've enabled all the required APIs on the Google Console, and created the Client ID for my app)
At this point i'm kind of lost.
Should I use directly the GoogleAuthUtil from the Google Play services lib? in this case once obtained the token as a String how can i use it with the YouTubeData APIs?
Or should I use the GoogleAccountCredential ? in this case someone knows how can I solve the "NeedPersmission : null" error?
---- EDIT:
details on what my app is trying to do: being this my first experience with this kind of APIs I started from the easy stuff: retrieve video information and then play those videos, without any user authentication. I managed to do that pretty easily, but for my app's purpose i need to access the user data, in particular users must be able to like and comment videos.
So I started implementing OAuth2, trying to do the same exact queries I was doing before (retrieve video info).
Wow. The documentation on this is super confusing. Full disclosure, I'm not an Android developer but I am a Java developer who has worked with Google apps and OAuth2.
Google Play or not Google Play? First off, Google Play Services will only be available on Android devices with Google Play Services installed (so not OUYA, Amazon devices, etc.). Google state that "the Google Play library will give you the best possible performance and experience.".
There are numerous discussions (e.g. here, here) from actual Android developers that list the various merits of Google Play verses other techniques. I would imagine that once you are able to get your application working using one method, then it should be an easy enough to change if you so desire.
Much of the example code about uses the Android AccountManager (Tasks and Calendars being favourite examples) so that is what I will show.
Your example code looks like it might be for a simple search, I would guess that many of the YouTube API interactions do not require OAuth2, in other code I've seen this empty HttpRequestInitializer implementation referred to as a no-op function. (e.g. GeolocationSearch.java).
It sounds like you want access to YouTube API operations that need account credentials. You can do something similar to this Android Calendar example (CalendarSampleActivity.java) except with YouTube, like the example answer from here.
// Google Accounts
credential = GoogleAccountCredential.usingOAuth2(this, YouTubeScopes.YOUTUBE, YouTubeScopes.YOUTUBE_READONLY);
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
// YouTube client
service =
new com.google.api.services.youtube.YouTube.Builder(transport, jsonFactory, credential)
.setApplicationName("Google-YouTubeAndroidSample/1.0").build();
I hope this helps.
In the initialize method of the HttpRequestInitializer you can set headers of the request. According to Googles documention for Oath2 for devices https://developers.google.com/identity/protocols/OAuth2ForDevices if you have an access token you should put it in the Authorization: Bearer HTTP header.
YouTube youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
request.put("Authorization", "Bearer " + yourAccessTokenString);
}
}).setApplicationName("AppName").build();
Remember the space after the Bearer in the authorization header value
I'm trying to get all the products listed by two companies by using the eBay api on my android phone. I do this by using the item filter but when I run this it will return product from all companies not from just from the companies I have stated. Why is this? Below is the http I send (MyAppIid is my actually Id and Seller1Name and Seller2Name are the companies I select)
http://open.api.ebay.com/finding?callname=findItemsAdvanced&responseencoding=JSON&appid=MyAppID&siteid=3&version=713&QueryKeywords=android&GLOBAL-ID=EBAY-UK%203g&itemFilter(0).name=Seller&itemFilter(0).value(0)=Seller1Namet&itemFilter(0).value(1)=Seller2Name
It seems that you try to use a mix of Shopping and Finding API. It's interesting that it works at all without an API error. In any case you should use the eBay Finding API for your purpose. Here is an example how the URL may look like:
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.13.0&SECURITY-APPNAME=YOUR_APP_ID_HERE&GLOBAL-ID=EBAY-GB&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsAdvanced&REST-PAYLOAD&itemFilter(0).name=Seller&itemFilter(0).value(0)=doria-store&itemFilter(0).value(1)=universalgadgets01&keywords=android&outputSelector(0)=SellerInfo
I've created an example in our Live API Playground. You can adapt the call to your needs and execute it to see the response directly in the response area. When you're done, click on "Retrieve JS code" and you will get ready-to-use JS code including the URL for the call with all its parameters you've configured.