使用开源项目google-api-ruby-client,我正在尝试运行OAuth 2.0示例calendar.rb,它将访问Google Calendar API.我在Google API控制台中创建了客户端ID,并在ruby脚本中填写客户端ID和密码.
但是,在我运行ruby脚本之后
ruby calendar.rb
Run Code Online (Sandbox Code Playgroud)
然后打开http:// localhost:4567,浏览器从Google向我返回错误信息:
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:4567/oauth2callback did not match a registered redirect URI
Run Code Online (Sandbox Code Playgroud)
我检查了Google API控制台中的信息:
Redirect URIs: https://localhost/oauth2callback
JavaScript origins: https://localhost
Run Code Online (Sandbox Code Playgroud)
有什么问题以及如何解决?提前致谢.
我是appEngine的新手,我尝试了我的项目所需的简单事情:我创建了简单的JDO类Image:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Image {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private Blob image;
@Persistent
private String type;
@Persistent
private String description;
public Key getKey() {
return key;
}
public void setKey(Key key) {
this.key = key;
}
public Blob getImage() {
return image;
}
public void setImage(URL url) throws IOException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
url.openStream()));
String line;
StringBuffer stbf = new StringBuffer();
while ((line = reader.readLine()) != null) { …Run Code Online (Sandbox Code Playgroud) google-app-engine google-api-client google-cloud-endpoints google-cloud-datastore
在我的代码中,google api客户端即使正在连接也会返回false值
GoogleApiClient mGoogleApiClient;
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG,"btn is clicked");
buildGoogleApiClient();
Log.i(TAG,"build google api completed");
mGoogleApiClient.connect();
if(mGoogleApiClient.isConnected())
Log.i(TAG,"client conneted");
Log.i(TAG,String.valueOf(mGoogleApiClient.isConnected()));
}
});
protected synchronized void buildGoogleApiClient() {
Log.i(TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我的服务器 Google App Engine API 代码和我的客户端都使用 python。我已经有很多客户端-服务器 GET 请求在工作,现在是 POST 请求的时候了,但我被卡住了。我的相关客户代码:
service = build("myAPI", "v1", http=http, discoveryServiceUrl=DISCOVERY_URL)
service.updateUser(websafeKey=websafeKey).execute()
Run Code Online (Sandbox Code Playgroud)
我不知道如何构建 POST 请求的正文。在那之后,我将被困在试图弄清楚如何告诉service它以便它可以将请求发送到我的 updateUser API。
POST 请求正文将需要包含一些字符串和几个列表,然后可能包含一个 python Date 对象。
我的updateUserAPI 在 API Explorer 中运行良好 - 我可以updateUser一整天都成功:
USER_POST_REQUEST = endpoints.ResourceContainer(
UserForm, websafeKey=messages.StringField(1),)
@endpoints.method(USER_POST_REQUEST, UserForm,
path='useradmin/{websafeKey}',
http_method='PUT', name='updateUser')
def updateUser(self, request):
"""Update user w/provided fields & return w/updated info."""
return self._updateUserObject(request)
Run Code Online (Sandbox Code Playgroud) 我正在将 Google Drive API 集成到我的 Android 应用程序中,以在 App Storage 文件夹中存储一个 JSON 文件。
为此,我在 MainActivity 的片段中实现了 Google Drive API。
当我执行此代码时,它按预期使用 SIGN_IN_REQUIRED 代码命中 onConnectionFailed 方法。我执行 startResolutionForResult 并出现帐户选择器。
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "GoogleApiClient connection failed: " + connectionResult.toString());
if (connectionResult.hasResolution()) {
if(!mConnectionResolutionInProgress)
{
try {
mConnectionResolutionInProgress = true;
connectionResult.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLUTION);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
showMessage("There was an issue connecting to Google Drive services.");
}
}
else
{
mConnectionResolutionInProgress = false;
showMessage("Canceling export/import …Run Code Online (Sandbox Code Playgroud) 在谷歌云存储中,我在名为图像的根存储桶中放置了名为猫的存储桶。我使用 google-api-ruby-client gem 上传文件。我可以将文件上传到根存储桶“images”,但无法上传到“images/cats”。我知道谷歌云存储中的存储桶没有斜线的概念,所以我无法弄清楚如何指定嵌套存储桶的名称。
result = client.execute(
api_method: api.objects.insert,
media: media,
parameters: {
uploadType: 'resumable',
bucket: 'images/cats', #This does not work !. Just images works.
name: 'kitty.jpeg',
},
body_object: {contentType: 'image/jpeg'}
)
Run Code Online (Sandbox Code Playgroud)
这给出了错误NoMethodError: undefined method query_values for nil:NilClass。如果我只使用“图像”作为存储桶的值,则该代码有效。
我怎样才能使上传工作也适用于嵌套存储桶?
谢谢
在 'com.google.android.gms:play-services-location:9.4.0'
无法导入导入
com.google.android.gms.location.places.Places
由于此无法构建GoogleApiClient且无法使用Places.GeoDataApi.getPlaceById.
但是'com.google.android.gms:play-services-location:8.4.0'我们可以正确使用它.
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId).setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
if (places.getStatus().isSuccess() && places.getCount() > 0) {
final com.google.android.gms.location.places.Place myPlace = places.get(0);
Log.i(TAG, "Place found: " + myPlace.getName());
map.addMarker(new MarkerOptions()
.position(myPlace.getLatLng())
.title(myPlace.getName().toString())
.snippet(myPlace.getAddress().toString()));
map.moveCamera(CameraUpdateFactory.newLatLng(myPlace.getLatLng()));
}
places.release();
}
});
Run Code Online (Sandbox Code Playgroud) android google-api-client google-places-api google-play-services
嘿伙计我有问题,当我创建一个新的Google Api客户端实例,并且我调用方法'.connect'时,我得到一个Exception,它说GoogleApiClient尚未连接.
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
//Setup LocationRequest
this.locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(1000 * 10)
.setInterval(1000 * 3);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
@Override
public void onStart(){
super.onStart();
this.googleApiClient.connect();
}
@Override
public void onStop(){
super.onStop();
this.googleApiClient.disconnect();
}
Run Code Online (Sandbox Code Playgroud)
例外:
08-27 22:54:04.536 11610-11610/at.ideafactory.spotted E/AndroidRuntime: FATAL EXCEPTION: main
Process: at.ideafactory.spotted, PID: 11610
java.lang.RuntimeException: Unable to start activity ComponentInfo{at.ideafactory.spotted/at.ideafactory.spotted.Activity.Main.MainActivity}: …Run Code Online (Sandbox Code Playgroud) 我使用范围:
但结果数据为:
不包含有关Google帐户中存在两因素身份验证的信息。我可以获取布尔值或其他值吗?
我跟着这个 Gmail API Python 快速入门教程:https : //developers.google.com/gmail/api/quickstart/python
我按照说明在 API 控制台中配置了我的 OAuth 客户端 ID(请参阅下面的第一张图片)。但是,启动脚本会打开一个浏览器会话,导致下面的 400 错误。
重定向 URL 与 API 控制台中注册的内容相匹配。
但是,快速入门脚本会打开以下 URL:https : //accounts.google.com/o/oauth2 ... & redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F ...
手动将重定向 URI 更改为http://localhost:8080部分解决了我处理授权请求时的问题,但随后无法将响应返回到命令提示符。
如何强制快速入门程序生成将重定向 URI 保留为http://localhost:8080的 URL ?