我正在使用Google API PHP客户端.每次我尝试登录时,我都被迫授予应用程序权限.
以下是我的代码.我基本上是访问Google API for Analytics
require_once 'lib/apiClient.php';
require_once 'lib/contrib/apiAnalyticsService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Google Analytics");
$client->setClientId('7xxxx');
$client->setClientSecret('xxxx');
$client->setRedirectUri('xxxx');
$client->setDeveloperKey('xxxx');
$analytics = new apiAnalyticsService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$profileId = getProfileIds($analytics);
echo "<select>";
foreach ($profileId as $profiles) {
echo "<option value=\"" . $profiles['profileId'] . "\">" . $profiles['name'] .
"</option>"; …Run Code Online (Sandbox Code Playgroud) 我查找并搜索了其他人,肯定是其他人正在使用API,在身份验证时,我似乎找不到正确的范围参数值:
我已经查看了所有这些作用域列表,没什么,尝试过OAuth 2.0游乐场,没有翻译。
任何线索都欢迎,谢谢。
错误信息:
Error: invalid_request
Missing required parameter: scope
Learn more
Request Details
Run Code Online (Sandbox Code Playgroud)
更新资料
用户Ezra解释说,翻译API不需要OAuth2身份验证。
我沿着这条路走这条路:
我正在尝试使示例代码在这里工作:
而且没有apiclient.discovery模块
from apiclient.discovery import build
Run Code Online (Sandbox Code Playgroud)
我去了寻找那它落在我这里这个快速启动配置 这给了我一个自动生成翻译API项目在这里:
这个应该为Translation API量身定制的入门项目包括一整套OAuth配置,因此由于这里提到的错误,我最终提出了一个问题
exception calling translation api: <HttpError 400 when requesting https://www.googleapis.com/language/translate/v2?q=zebra&source=en&alt=json&target=fr&key=MYSECRETKEYWENTHERE returned "Bad Request">
Run Code Online (Sandbox Code Playgroud)
我用来进行上述调用的代码,这种方式的错误是:
service = build('translate', 'v2',
developerKey='MYSECRETKEYWENTHERE')
result = service.translations().list(
source='en',
target=lang,
q='zebra'
).execute()
Run Code Online (Sandbox Code Playgroud)
如果我直接拨打该错误抱怨的电话,那就可以了
https://www.googleapis.com/language/translate/v2?key=MYSECRETKEYWENTHERE&q=zebra&target=fr&alt=json&source=en
Run Code Online (Sandbox Code Playgroud)
再次更新
好的,我从示例项目中删除了所有OAuth代码,然后再次运行它,最后发现我的密钥中有错字...
感谢您的回答!
。
谢谢
google-app-engine oauth-2.0 google-api-client oauth2client oauth2-playground
我目前正在考虑使用 nodejs 客户端实现 google api:
https://github.com/google/google-api-nodejs-client/
我正在尝试使用护照进行身份验证,这似乎有效@
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function () {
var user = {
id: profile.id,
email: profile.email,
firstName: profile.given_name,
lastName: profile.family_name,
accessToken: accessToken
};
return done(null, user);
});
}
));
Run Code Online (Sandbox Code Playgroud)
在我的谷歌身份验证回调中:
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
//do something here with the google api
});
Run Code Online (Sandbox Code Playgroud)
我可以拿到req.user,这个有accessToken
但是,Google api Nodejs 客户端的文档并不清楚如何使用 accessToken。包含的示例显示 OAauth2Client 检索令牌,但我猜该部分已经使用 Passport 涵盖了?
我有一个保存的地理位置(纬度,经度)。当用户按下应用程序中的操作按钮时,当前位置被记录下来。
我想检查当前的纬度、经度(我拥有的)是否落在圆形地理围栏(我拥有的中心地理点)中。
我不想在 Google 地图上创建地理围栏。我只想检查地理定位是否属于地理围栏。
当精度小于 20 时,我用来获取当前地理位置的代码:
public class CreatePlaceActivity extends Fragment implements
OnClickListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
private Button cancelBtn, submitBtn;
public boolean geoLocationCheck = false;
private String TAG = "CreatePlaceActivity";
public CreatePlaceActivity() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.create_place_screen,
container, false);
submitBtn = (Button) rootView.findViewById(R.id.submit_btn_id);
submitBtn.setTypeface(typeface);
submitBtn.setOnClickListener(this);
cancelBtn = (Button) rootView.findViewById(R.id.cancel_btn_id);
cancelBtn.setOnClickListener(this);
setlocationClient();
return rootView;
}
private void setlocationClient() {
int resp = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getActivity());
if …Run Code Online (Sandbox Code Playgroud) 我正在为我的安全后端服务器将 AndroidPublisher 库从 v1 升级到 v3。AndroidPublisher 库 (v3) 将允许我安全地对应用内购买和订阅进行服务器端购买验证和确认。
v1 的现有代码不再兼容。v3 库看起来更好,但我找不到任何示例代码:
Get&Acknowledge使用 PurchaseToken 购买。Maven 设置:
<project>
<dependencies>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidpublisher</artifactId>
<version>v3-rev103-1.25.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.30.2</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
API 文档:https : //developers.google.com/android-publisher/api-ref/purchases/products/get
寻找这样的示例:https : //developers.google.com/api-client-library/java/google-api-java-client/samples
任何简短的示例代码都会有很大帮助。
我希望我的服务帐户能够模拟 GSuite 中的用户之一。我有
domain-wide delegation在服务帐户设置中启用GCPAPI Client添加了service account idGSuite在浏览文档(java)时,我看到了这个
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json"))
.createScoped(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
.createDelegated("user@example.com");
Run Code Online (Sandbox Code Playgroud)
在这里,他们指定服务帐户应模拟哪个用户。这段代码是java中的。我需要在nodejs 中完成同样的事情。
在查看nodejs-clientfor的文档时googleapis,我发现了这一点:
const {google} = require('googleapis');
const auth = new google.auth.GoogleAuth({
keyFile: '/path/to/your-secret-key.json',
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
Run Code Online (Sandbox Code Playgroud)
和
const {google} = require('googleapis');
const oauth2Client = new google.auth.OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
YOUR_REDIRECT_URL
);
// set auth as a global default
google.options({
auth: oauth2Client
});
Run Code Online (Sandbox Code Playgroud)
GoogleAuth和这里有什么区别OAuth2 …
node.js google-api-client google-api-nodejs-client gmail-api
我正在使用此处示例中的代码:http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_python.html#Auth
仍然没有骰子.
这是我得到的确切代码(这都是在Web服务器上运行):
#!/usr/bin/python
import gdata.photos.service
import gdata.media
import gdata.geo
print "content-type:text/html\n"
def GetAuthSubUrl():
next = 'http://my_domain.com/foo/connect_picasa.cgi'
scope = 'http://picasaweb.google.com/data/'
secure = False
session = True
gd_client = gdata.photos.service.PhotosService()
return gd_client.GenerateAuthSubURL(next, scope, secure, session);
authSubUrl = GetAuthSubUrl();
print '<a href="%s">Login to your Google account</a>' % authSubUrl
Run Code Online (Sandbox Code Playgroud)
然后my_domain/foo/connect_picasa.cgi我有:
#!/usr/bin/python
import gdata.photos.service
import gdata.media
import gdata.geo
import cgi
parameters = cgi.FieldStorage()
authsub_token = parameters['token']
print "content-type:text/html\n"
#debugging
print authsub_token
gd_client = gdata.photos.service.PhotosService()
gd_client.auth_token = authsub_token
gd_client.UpgradeToSessionToken()
#more …Run Code Online (Sandbox Code Playgroud) 我的情况:
我的顾虑:
在com.google.android.gms.common.api.GoogleApiClient和com.google.android.gms.common.GooglePlayServicesClient命名空间凭借事实,如果你想使用介绍一些重叠GoogleApiClient和LocationClient,那么你的类(即Activity)必须实现以下几点:
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener
Run Code Online (Sandbox Code Playgroud)来自两个名称空间的代码将覆盖以下内容:
@Override
public void onConnected(Bundle connectionHint) {
/* pseudo-code
if (GoogleApiClient) {
// Implementation
} else {
// Must be LocationClient
}
*/
}
@Override
public void onConnectionFailed(ConnectionResult result) {
/* pseudo-code
if (GoogleApiClient) {
// Implementation
} else {
// Must be LocationClient
}
*/
}
Run Code Online (Sandbox Code Playgroud)
这样,你将被迫写代码来辨别它是否是 …
android separation-of-concerns google-api-client google-play-services location-client
我正在尝试使用ASP.NET Web Form在我的YouTube频道上传视频.我创建了开发人员帐户,并使用基于JavaScript的解决方案进行了测试,该解决方案需要每次登录才能上传视频.
我希望我的网站用户直接在我的频道上传视频,并且每个身份验证应该在代码后面,不应提示用户登录.为此,我写了以下课程:
public class UploadVideo
{
public async Task Run(string filePath)
{
string CLIENT_ID = "1111111111111111111111.apps.googleusercontent.com";
string CLIENT_SECRET = "234JEjkwkdfh1111";
var youtubeService = AuthenticateOauth(CLIENT_ID, CLIENT_SECRET, "SingleUser");
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Default Video Title";
video.Snippet.Description = "Default Video Description";
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
using (var fileStream = new …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc google-api google-api-client google-api-dotnet-client
我试图使用google sheet API for iOS进行批量更新,但在'data [0] .values [0]'(type.googleapis.com/google.protobuf.ListValue)上收到错误无效值,
这是我的代码
NSString *baseUrl = @"https://sheets.googleapis.com/v4/spreadsheets/";
NSString *spreadsheetId = @"1tJd4toWFxmHAEOeONauRPcuH_rWJOESLQT7TvCIK0x0";
baseUrl= [baseUrl stringByAppendingString:spreadsheetId];
baseUrl = [baseUrl stringByAppendingString:@"/values:batchUpdate/"];
NSMutableDictionary * params=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"USER_ENTERED",@"valueInputOption", nil];
NSURL *postURL=[GTLUtilities URLWithString:baseUrl queryParameters:params];
NSLog(@"base url is %@", postURL);
GTLObject * body=[[GTLObject alloc]init];
NSMutableArray * titleArray=[[NSMutableArray alloc]initWithObjects:@"Customer ID",@"Customer Name",@"Latitude",@"Longitude" ,@"Last_Updated_At",nil];
NSMutableArray * wheelArray2=[[NSMutableArray alloc]initWithObjects:@"rt",@"SHJ",@"150.00",@"100.00",@"2:00:00", nil];
//[contentArray addObject:titleArray];
NSMutableDictionary * batchParams=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"USER_ENTERED",@"valueInputOption", nil];
NSMutableArray * batchParametersContentArray=[[NSMutableArray alloc]init];
NSMutableDictionary* batchParametersTitlesDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Sheet1!A1:E1",@"range",@"COLUMNS",@"majorDimension",titleArray,@"values", nil];
NSMutableDictionary* batchParametersContentDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Sheet1!A7:E7",@"range",@"ROWS",@"majorDimension",wheelArray2,@"values", nil];
[batchParametersContentArray addObject:batchParametersTitlesDict];
[batchParametersContentArray addObject:batchParametersContentDict];
[batchParams setObject:batchParametersContentArray forKey:@"data"]; …Run Code Online (Sandbox Code Playgroud) google-api ×4
android ×2
node.js ×2
asp.net ×1
asp.net-mvc ×1
gmail-api ×1
ios ×1
java ×1
oauth-2.0 ×1
oauth2client ×1
passport.js ×1
php ×1
python ×1
server ×1