标签: google-api-client

gapi.client.load无法正常工作

我有以下代码,这应该是使用google api javascript客户端的简单示例,并且只显示硬编码缩短URL的长格式URL:

<script>
  function appendResults(text) {
    var results = document.getElementById('results');
    results.appendChild(document.createElement('P'));
    results.appendChild(document.createTextNode(text));
  }

  function makeRequest() {

    console.log('Inside makeRequest');

    var request = gapi.client.urlshortener.url.get({
      'shortUrl': 'http://goo.gl/fbsS'
    });

    request.execute(function(response) {
      appendResults(response.longUrl);
    });
  }

  function load() {

    gapi.client.setApiKey('API_KEY');
    console.log('After attempting to set API key');
    gapi.client.load('urlshortener', 'v1', makeRequest);
    console.log('After attempting to load urlshortener');
  }
</script>
<script src="https://apis.google.com/js/client.js?onload=load"></script>
Run Code Online (Sandbox Code Playgroud)

除了使用实际的API密钥而不是文本"API_KEY".

控制台输出简单:

尝试设置API密钥后

尝试加载urlshortener后

但我从来没有看到'inside makeRequest',它位于makeRequest函数内部,这是调用gapi.client.load的回调函数,让我相信函数无法正常工作(或者无法完成).

任何人都可以阐明为什么会这样,以及如何解决它?

提前致谢.

javascript google-api url-shortener google-url-shortener google-api-client

3
推荐指数
2
解决办法
6159
查看次数

是否可以同时执行从同一个Storage对象创建的Insert对象?

我正在使用Google的Java API来使用Google云端存储(GCS).

我有多个工作线程将对象插入GCS.目前,它们共享一个公共Storage实例,并使用它来创建Storage.Object.Insert实例:

synchronized(LOCK)
{
    insertObject = mStorage.objects().insert(mBucketName, objectMetadata, mediaContent);
}
Run Code Online (Sandbox Code Playgroud)

后来,他们打电话execute()Insert情况下,将文件上载到GCS.

insertObject.execute();
Run Code Online (Sandbox Code Playgroud)

我的问题是我可以execute()在不同的线程中同时运行调用吗?该Insert对象对于该线程是唯一的,但Storage它创建的对象是在线程之间共享的,所以我担心这可能会导致问题.

提前致谢!

java google-api-java-client google-api-client google-cloud-storage

3
推荐指数
1
解决办法
509
查看次数

如何通过Drive API(PHP客户端)创建公共Google Doc

这就是我到目前为止,结合这个这个:

require_once "google-api-php-client/src/Google_Client.php";
require_once "google-api-php-client/src/contrib/Google_DriveService.php";
require_once "google-api-php-client/src/contrib/Google_Oauth2Service.php";

//First, build a Drive service object authorized with the service accounts
$auth = new Google_AssertionCredentials(
    DRIVE_SERVICE_ACCOUNT_EMAIL,
    array( DRIVE_SCOPE ),
    file_get_contents( DRIVE_SERVICE_ACCOUNT_KEY )
);
$client = new Google_Client();
$client->setUseObjects( true );
$client->setAssertionCredentials( $auth );
$service = new Google_DriveService( $client );

//Then, insert the file
$file = new Google_DriveFile();
$file->setTitle( 'My document' );
$file->setMimeType( 'text/plain' );
$createdFile = $service->files->insert( $file, array(
    'data' => 'Hello world!',
    'mimeType' => 'text/plain',
));

print_r( $createdFile …
Run Code Online (Sandbox Code Playgroud)

google-api google-api-client google-drive-api google-api-php-client

3
推荐指数
1
解决办法
5661
查看次数


GoogleApiClient无法连接

我想使用FusedLocationProviderApi来获取最后的已知位置.我就像Google教程所说的那样,但似乎GoogleApiClient没有连接,至少它不会触发onConnected和onConnectionFailed方法.我希望你能提前帮助我.

import com.example.stoos.data.DataModelOrt;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
.
.
.
public class OrtHinzufugen extends Activity  implements
ConnectionCallbacks, OnConnectionFailedListener{
.
.
.
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ort_auswahlen);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    buildGoogleApiClient();
.
.
.
}
protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API) …
Run Code Online (Sandbox Code Playgroud)

android google-api-client fusedlocationproviderapi

3
推荐指数
1
解决办法
1770
查看次数

在Laravel 5中使用Google Drive Api

我是Laravel的新手,肯定这个问题有一个明显的答案,但我无法将Laravel 5与Google Api联系起来.

我总是像编辑器一样安装Api,它在我的供应商文件夹中,但现在我不知道如何使用它.

我没有找到答案(因为这一定非常简单).

可能我错过了一个命名空间调用,或类似的东西.

在我的IndexController上,我有:

    <?php 

namespace App\Http\Controllers;

class IndexController extends Controller {

    /**
     * Show the application welcome screen to the user.
     *
     * @return Response
     */
    public function index()
    {
      $client = new Google_Client();
      $client->setApplicationName("Client_Library_Examples");
      $client->setDeveloperKey("HERE_GOES_MY_KEY");

      $service = new Google_Service_Drive($client);
      $results = $service->volumes->listVolumes();

      foreach ($results as $item) {
        echo $item['volumeInfo']['title'], "<br /> \n";
      }
    }

}
Run Code Online (Sandbox Code Playgroud)

而我得到的错误是:

找不到"App\Http\Controllers\Google_Client"类

我认为这可能是autoload_classmap的问题,但是定义了所有GoogleApi类,例如:

(......)

'Google_Client'=> $ vendorDir.'/google/apiclient/src/Google/Client.php',

(......)

'Google_Service_Drive'=> $ vendorDir.'/google/apiclient/src/Google/Service/Drive.php',

感谢您的耐心和帮助!

php vendor google-api-client laravel-5

3
推荐指数
1
解决办法
6813
查看次数

GoogleApiClient尚未连接,即使已调用onConnected并且我正在onCreate中创建我的GoogleApiClient

我在这里查看了这个问答:GoogleApiClient正在抛出"GoogleApiClient尚未连接"之后onConnected函数被调用

因为它似乎与我所经历的相似,但事实并非如此.该用户的问题是他们在onStart()方法中声明了他们的api客户端,我在onCreate()方法中创建了我的答案.然而,我仍然得到同样的错误.

以下是我对这三种方法的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /* Butter knife creates the variables */
    ButterKnife.bind(this);

    /* Startup location services */
    locationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000)        // 10 seconds, in milliseconds
            .setFastestInterval(1 * 1000); // 1 second, in milliseconds

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    progressBar.setVisibility(View.INVISIBLE);

    refreshImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getForecast();
        }
    });
}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
    Log.i("Connected!!!", "WERE CONNECTED");
}

@Override
protected void …
Run Code Online (Sandbox Code Playgroud)

java android location google-api-client

3
推荐指数
1
解决办法
3136
查看次数

GoogleApiClient具有可选的Plus.API,并且未与Play服务8.3中引入的新Google标志连接到Plus

当我尝试使用Plus'Heople Api来访问用户的基本个人资料信息时,我收到很多关于我的应用程序崩溃的报告.

这是我的GoogleApiClient设置

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestScopes(new Scope(Scopes.PROFILE))
                    .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                    .requestIdToken(<id_token>)
                    .requestProfile()
                    .build();

mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .addApi(Plus.API)
                    .addConnectionCallbacks(this)
                    .build();
Run Code Online (Sandbox Code Playgroud)

在此行上获取IllegalStateException:

Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClientPlus)
Run Code Online (Sandbox Code Playgroud)

java.lang.IllegalStateException:GoogleApiClient具有可选的Plus.API,并且未连接到Plus.使用GoogleApiClient.hasConnectedApi(Plus.API)来保护此通话.

此代码仅在google登录后使用已登录用户返回时调用.那么为什么不能连接api?

android google-api-client google-play-services google-plus-signin google-signin

3
推荐指数
1
解决办法
4463
查看次数

在Android应用程序中注销GoogleApiClient

使用此类代码可以链接我的应用程序和使用帐户.

if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Plus.API)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mGoogleApiClient.connect();
Run Code Online (Sandbox Code Playgroud)

但是,一旦激活或切换到新帐户,该帐户是否有任何"退出"的方式?

android google-api google-api-client

3
推荐指数
2
解决办法
8483
查看次数

Googleapiclient和python3

我编写了一个使用Google表格API的基本Python 3脚本.它适用于默认为Python 3(Arch)的系统.我正在尝试在Ubuntu 14.04系统上运行相同的脚本,但我无法加载apiclient库.我安装了推荐 pip install --upgrade google-api-python-client 但是我注意到我只能在python 2中加载库.

这是我正在观察的内容:

~ $ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from googleapiclient import discovery
>>> quit()
~ $ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from googleapiclient import discovery
Traceback (most recent call last):
  File "<stdin>", line 1, in <module> …
Run Code Online (Sandbox Code Playgroud)

python debian google-api-client

3
推荐指数
1
解决办法
3225
查看次数