小编Hux*_*ley的帖子

使用带有php脚本的google驱动器api自动刷新令牌

我再次跟踪本教程,使用php直接从我的REMOTE SERVER上传Google文件:所以我从Google API控制台创建了新的API项目,启用了Drive API服务,请求了OAuth客户端ID和客户端密钥,并在脚本,然后将其与Google API Client Library for PHP文件夹一起上传到此http://www.MYSERVER.com/script1.php,以检索验证码:

<?php

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

$drive = new Google_Client();

$drive->setClientId('XXX'); // HERE I WRITE MY Client ID

$drive->setClientSecret('XXX'); // HERE I WRITE MY Client Secret

$drive->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');

$drive->setScopes(array('https://www.googleapis.com/auth/drive'));

$gdrive = new Google_DriveService($drive);

$url = $drive->createAuthUrl();
$authorizationCode = trim(fgets(STDIN));

$token = $drive->authenticate($authorizationCode);

?>
Run Code Online (Sandbox Code Playgroud)

当我访问http://www.MYSERVER.com/script1.php时,允许授权并获取我可以在第二个脚本中编写的Auth代码.然后我将其上传到http://www.MYSERVER.com/script2.php,看起来像:

<?php

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

$drive = new Google_Client();

$drive->setClientId('X');  // HERE I WRITE MY Client ID …
Run Code Online (Sandbox Code Playgroud)

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

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

从objective-c中解析的NSString中提取单个值

这些是我的示例NSStrings(解析成数组),简化.

单个字符串对象被解析为"STRING1,STRING2然后DATE TIME然后 - A:VALUE",例如:

The name of first value, first 17/04/2013 11:30:00 - A:30.0 // sometimes there is a comma after first string
The name of second value 17/04/2013 11:00:00 - A:20.0 // sometimes there is NOT a comma after first string
Name of third value 17/04/2013 10:30:00 - A:40.0
Fourth 17/04/2013 09:40:00 - A:50.0
Fifth value 17/04/2013 05:00:00 - A:10.0
Run Code Online (Sandbox Code Playgroud)

好吧,我需要提取STRING或STRING的单独值,STRING:

The name of first value, first
The name of second value
Name of third value
Fourth
Fifth …
Run Code Online (Sandbox Code Playgroud)

regex objective-c nsstring nsarray nsregularexpression

7
推荐指数
1
解决办法
5871
查看次数

Objective OA中的Twitter OAuth和accessToken到GET状态/ user_timeline

我正试图从Twitter获取accessToken值,以便在我的应用程序中使用它(我需要使用API​​ v1.1的GET状态/ user_timeline的身份验证模型); 我在api.twitter.com上注册了我的应用程序,在项目中导入了AFOAuth1Client类,这是一个简单的代码:

- (void)viewDidLoad
{
    self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:
                                     [NSURL URLWithString:@"https://api.twitter.com/"] key:@"MYKEY" secret:@"MYSECRETKEY"];
    AFOAuth1Token *accessToken;

    [self.twitterClient acquireOAuthAccessTokenWithPath:@"oauth/request_token" requestToken:accessToken accessMethod:@"GET" success:^(AFOAuth1Token *accessToken) { // I have tried also accessMethod: @"POST"
        NSLog(@"Success: %@", accessToken);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,XCode给了我这个错误:

Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x79a14f0 {NSLocalizedRecoverySuggestion=Failed to validate oauth signature and token, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7956390>
Run Code Online (Sandbox Code Playgroud)

这有什么不对?我需要在api.twitter.com上注册应用程序吗?它是正确的方式,或者,在iOS中使用API​​ v1.1的Twitter身份验证模型获取状态/ user_timeline的简单方法是什么?谢谢!

编辑:可能的航点?

1)在dev.twitter.com上注册一个新的应用程序

2)在OAuth设置中,读取Consumer密钥和Consumer secret

3)设置默认的app访问类型来读取?或读/写?要求获取令牌?在...中使用这个值?

twitter oauth objective-c access-token afnetworking

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

解析后,UITableView委托和数据源在单独的类中

我需要从一个单独的类设置我的UITableView委托和数据源(通过方法调用解析后的数据就绪),但每次我的表都是emtpy时.我正在使用ARC,这是简化的代码:

//HomeViewController.h

#import <UIKit/UIKit.h>
#import "TableController.h"

@interface HomeViewController : UIViewController {

    IBOutlet UITableView *table;
    TableController *tableController;
}

@end
Run Code Online (Sandbox Code Playgroud)

//HomeViewController.m

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    tableController = [[TableController alloc] init];
    table.dataSource = tableController.tableSource.dataSource;
    table.delegate = tableController.tableSource.delegate;
    [tableController loadTable]; // HERE I CALL LOADTABLE FROM TABLECONTROLLER CLASS TO PARSE DATA AND POPULATE UITABLEVIEW
    [table reloadData];

}
Run Code Online (Sandbox Code Playgroud)

// TableController.h

#import <UIKit/UIKit.h>

@interface TableController : NSObject <UITableViewDelegate, UITableViewDataSource> {

   UITableView *tableSource;

   // a lot …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uitableview

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

"PHP致命错误:在Google Drive php UPDATE脚本中调用非对象上的成员函数setTitle()

我正在使用这个PHP脚本将文件INSERT(上传)到我的Google云端硬盘,它的完美:

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

$drive = new Google_Client();

$drive->setClientId('XXX');
$drive->setClientSecret('YYY');
$drive->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$drive->setScopes(array('https://www.googleapis.com/auth/drive'));

$gdrive = new Google_DriveService($drive);

$drive->setAccessToken(file_get_contents('token.json'));

$doc = new Google_DriveFile();

$doc->setTitle('Test');
$doc->setDescription('Test Document');
$doc->setMimeType('text/plain');

$content = file_get_contents('test.txt');

$output = $gdrive->files->insert($doc, array(
      'data' => $content,
      'mimeType' => 'text/plain',
    ));

print_r($output);
Run Code Online (Sandbox Code Playgroud)

现在我想更新(不上传)我现有的Google云端硬盘文件,我正在使用此脚本:

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

$drive = new Google_Client();

$drive->setClientId('XXX');
$drive->setClientSecret('YYY');
$drive->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$drive->setScopes(array('https://www.googleapis.com/auth/drive'));

$gdrive = new Google_DriveService($drive);

$drive->setAccessToken(file_get_contents('token.json'));

$fileId = "ZZZ";
$doc = $gdrive->files->get($fileId);

$doc->setTitle('Test'); // HERE I GET THE ERROR "CALL TO A MEMBER …
Run Code Online (Sandbox Code Playgroud)

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

0
推荐指数
1
解决办法
2384
查看次数