使用以下代码,我可以上传到谷歌云存储中的公共可写桶.(allUsers有写权限).但是,如果存储桶不可公开写入,那么我会收到401未经授权的错误.(我不希望桶是公开可写的).
var file = $scope.myFile;
var fileData = file;
var boundary = '-------314159265358979323846';
var delimiter = "\r\n--" + boundary + "\r\n";
var close_delim = "\r\n--" + boundary + "--";
var reader = new FileReader();
reader.readAsBinaryString(fileData);
reader.onload = function(e) {
var contentType = fileData.type || 'application/octet-stream';
var metadata = {
'name': 'objectName', //'lol' + fileData.name,
'mimeType': contentType
};
var base64Data = btoa(reader.result);
var multipartRequestBody =
delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(metadata) +
delimiter +
'Content-Type: ' + contentType + '\r\n' + …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取位置更新信息.为此,我创建了一个服务,在服务类的onStartCommand中我正在创建GoogleApiClient,但我没有在服务中获得连接回调.请帮忙解决这个问题.
下面给出的是服务代码和活动我已经使用startService方法启动了服务:
startService(new Intent(this, LocationService.class));
Run Code Online (Sandbox Code Playgroud)
服务代码
public class LocationService extends Service implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleApiClient mLocationClient;
private Location mCurrentLocation;
LocationRequest mLocationRequest;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO do something useful
Toast.makeText(this, "onStartCommand", Toast.LENGTH_SHORT).show();
mLocationClient = new GoogleApiClient.Builder(LocationService.this)
.addApi(LocationServices.API).addConnectionCallbacks(LocationService.this)
.addOnConnectionFailedListener(LocationService.this).build();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setFastestInterval(1000);
return Service.START_NOT_STICKY;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mCurrentLocation = location;
Toast.makeText(this, mCurrentLocation.getLatitude() +", "+ mCurrentLocation.getLatitude(), Toast.LENGTH_SHORT).show();
}
@Override …Run Code Online (Sandbox Code Playgroud) 嗨,我正在研究我已集成BigQuery的Android应用程序.我看到有时在BigQuery表中插入记录时会遇到很多异常.我们不是这方面的专长,而是开始学习这项新技术.如果你们可以帮助我,那将是很棒的.
java.net.UnknownHostException: Unable to resolve host "accounts.google.com": No address associated with hostname
at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:254)
at com.google.a.a.c.a.c.a(NetHttpRequest.java:77)
at com.google.a.a.c.r.p(HttpRequest.java:972)
at com.google.a.a.a.a.h.a(TokenRequest.java:307)
at com.google.a.a.b.a.a.b.f(GoogleCredential.java:384)
at com.google.a.a.a.a.c.h(Credential.java:489)
at com.google.a.a.a.a.c.a(Credential.java:217)
at com.google.a.a.c.r.p(HttpRequest.java:859)
at com.google.a.a.b.d.c.c(AbstractGoogleClientRequest.java:469)
at com.test.utils.c.c(CommonUtility.java:2730)
at com.test.services.AppInstallIntentService.onHandleIntent(AppInstallIntentService.java:71)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Posix.java)
at …Run Code Online (Sandbox Code Playgroud) java android google-api-java-client google-api-client google-bigquery
我使用GoogleApiClient使用他们的Google帐户登录用户.基本上,我使用Firebase Auth与Google登录.
但我每天都会在某些设备上崩溃.当我在我自己的一些设备(OnePlus 3,Nexus 5X,Moto G等)上进行测试时,我从未看到过这种崩溃.
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase(java.util.Locale)' on a null object reference
at com.google.android.gms.internal.zzamy.zzd(Unknown Source)
at com.google.android.gms.internal.zzamv.n(Unknown Source)
at com.google.android.gms.internal.zzamv.zza(Unknown Source)
at com.google.android.gms.internal.zzamv$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java:818)
Run Code Online (Sandbox Code Playgroud)
这就是我正在做的实例化GoogleApiClient.我没有看到正常情况下的崩溃,但在某些设备中我看到了这一点.这是我在代码中所做的事情,
String mClientId = parcel.getProviderExtra().getString(CLIENT_ID_KEY);
GoogleSignInOptions googleSignInOptions;
googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(mClientId)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(App.getContext())
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
mGoogleApiClient.connect();
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?我最好的选择是,App.getContext()它为应用程序上下文提供实例化客户端.这可能是问题吗?
我可以使用活动上下文,但使用它会导致内存泄漏.这里有什么问题,如何解决?
对于在打开应用程序并尝试唱歌之后发生崩溃的用户,这会产生非常糟糕的体验.
android google-api-java-client google-api-client firebase firebase-authentication
似乎没有(据我所知)编辑Google文档的API(不是电子表格,它们基于HTML的文档).有没有人做过类似的事情?也许通过下载HTML版本,编辑和上传更改?
google-api google-docs google-docs-api google-apps-script google-api-client
我只是想做一个简单的"教程"应用程序来获取我的手机的位置(以便在以后的其他应用程序中学习如何使用它),但我只是没有到达任何地方.
Android Developer的教程:首先,我按照Android开发者网站(developer.android.com/training/location/receive-location-updates.html)中的教程进行操作.
就像那里所示,我使用了Location,LocationClient和LocationRequest,在onCreate中初始化它们(并设置它们).LocationClient在onStart和onStop上连接和断开连接.
我在连接后请求位置更新(在onConnected中).我在进行此调用之前验证了GooglePlayServices是否可用,而且我仍然没有在"onLocationChanged"中获得任何更新.
GoogleApiClient:我注意到不推荐使用LocationClient,而首选的是LocationServices(developer.android.com/reference/com/google/android/gms/location/LocationClient.html).
如下所示:https://developer.android.com/reference/com/google/android/gms/location/FusedLocationProviderApi.html,我使用GoogleApiClient并将其设置为LocationServices(也是/sf/answers/1750969531/).所以我把它全部设置为使用它,但我仍然没有得到任何关于位置的更新.
onLocationChanged如果有响应则应该打印.我还放了一个打印位置或"没有"的按钮.
我检查了使用谷歌地图,看看我是否有一些东西,但它的工作正常.
的build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:5.0.77'
compile "com.android.support:support-v4:20.0.+"
}
Run Code Online (Sandbox Code Playgroud)
表现
...
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
...
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
Run Code Online (Sandbox Code Playgroud)
码
public class MyActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
private GoogleApiClient mLocationClient;
private Location mCurrentLocation;
LocationRequest mLocationRequest;
...
/* Constant fields - request interval */
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mLocationClient …Run Code Online (Sandbox Code Playgroud) android location android-location google-api-client google-play-services
我一直在使用GoogleApiClientInterval和Displacement 更新来处理和测试背景位置更新.在测试和分析几天后,我发现输出中的一些变化,我没想到.
在使用setInterval和setFastestInterval基于Interval的更新时,比如说我将Interval设置为15分钟,将Fastest Interval设置为10分钟,90%的时间我在预期的间隔(10到15分钟)内获得更新.但有时我注意到更新所需的时间比指定的Interval长得多,例如,差异大约是30分钟和60分钟.关于为什么差异的任何想法?
在使用setMinimumDisplacement基于距离的更新时,比如说我已将Displacement设置为200米,我只能在200米及以上的静止点上进行更新(当旅行时,即使超过200米也没有更新).这是正常的吗?
我正在使用PendingIntent位置请求类型,以便BroadcastReceiver在后台接收位置更新的位置更新.
fusedLocationProviderClient.requestLocationUpdates(locationRequest, pendingIntent);
Run Code Online (Sandbox Code Playgroud)
测试时,位置服务已开启,位置模式为HIGH_ACCURACY.
我正在尝试将文件上传到我的 Google 驱动器,下面的代码有效。如何指定要上传到哪个文件夹,即驱动器---与我共享--csvFolder
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file2 = drive.CreateFile()
file2.SetContentFile('new_test.csv')
file2.Upload()
Run Code Online (Sandbox Code Playgroud) 我正在按照此处的教程(https://cloud.google.com/ai-platform/training/docs/training-jobs#python_1)并使用Python将机器学习模型部署到Google云进行训练。但是,我收到 HttpError 403:“资源项目 my_project 的权限被拒绝。” 错误的原因是“CONSUMER_INVALID”。具体来说,返回的元数据显示使用者是“projects/my_project”,服务是“ml.googleapis.com”。
我去了AI平台,我的项目确实在那里。我请求使用的 API 已为该项目启用,并且环境变量 GOOGLE_APPLICATION_CREDENTIALS 已正确设置。我想知道如何解决这个问题。谢谢!
google-api-client google-api-python-client google-ai-platform
Google 最近向我发送了一封电子邮件,其中包含以下内容:
您的一个或多个 Web 应用程序使用旧版 Google 登录 JavaScript 库。请在 2023 年 3 月 31 日之前将您的项目迁移到新的 Google Identity Services SDK
该项目使用 Google Drive API 以及现在的旧版身份验证客户端。
迁移页面( https://developers.google.com/identity/gsi/web/guides/migration )上的表格显示:
| 老的 | 新的 | 笔记 |
|---|---|---|
| JavaScript 库 | ||
| apis.google.com/js/platform.js | account.google.com/gsi/client | 以新换旧。 |
| apis.google.com/js/api.js | account.google.com/gsi/client | 以新换旧。 |
我目前正在gapi前端使用来执行从apis.google.com/js/api.js. 根据该表,我需要将其替换为新库。
我尝试了以下方法来进行身份验证和授权,其方式与我以前对gapi进行的操作相同:
window.google.accounts.id.initialize({
client_id: GOOGLE_CLIENT_ID,
callback: console.log,
scope: "https://www.googleapis.com/auth/drive.file",
discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"],
});
window.google.accounts.id.renderButton(ref.current, {
size: "medium",
type: "standard",
});
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用 Google 登录按钮进行身份验证时,该scope字段不受尊重,并且不会要求用户授权所请求的范围。它也不会在回调的凭据响应中返回任何形式的访问令牌。
我不知道如何授权使用新库。
javascript google-api google-api-client google-oauth google-identity
android ×5
google-api ×2
javascript ×2
cors ×1
firebase ×1
fusedlocationproviderclient ×1
google-docs ×1
google-oauth ×1
java ×1
location ×1
pydrive ×1
python ×1