Confusion with Thu Johns Twitter Laravel 4 PHP package - php

I am trying to use thu john's twitter-laravel package. I am trying to dynamically set the access tokens and then get the user's home timeline. It says that the method doesn't exist. But I know for sure the method exists in the Twitter class. It is giving me this error.
Error:
Call to undefined method
Thujohn\Twitter\TwitterFacade::getHomeTimeline()
My code:
$config = array(
'ACCESS_TOKEN' => 'xxx',
'ACCESS_TOKEN_SECRET' => 'xxxx'
);
$tw = new Twitter($config);
return $tw->getHomeTimeline(array('count' => 20, 'format' => 'json'));

Related

bigcommerce rest api v3 php

I have to implement bigcommerce API integration with PHP
and I am trying to use the official library from https://github.com/bigcommerce/bigcommerce-api-php
and I am not even able to start step 1 here.
Issues:
Basic Auth method
Bigcommerce::configure(array(
'store_url' => 'https://store.mybigcommerce.com',
'username' => 'admin',
'api_key' => 'd81aada4xc34xx3e18f0xxxx7f36ca'
));
So the question here is how to get a username? bigcommerece user only created using email address so how to get username here?
OAuth method
In order to obtain the auth_token you would consume Bigcommerce::getAuthToken method
$object = new \stdClass();
$object->client_id = 'xxxxxx';
$object->client_secret = 'xxxxx;
$object->redirect_uri = 'https://app.com/redirect';
$object->code = $request->get('code');
$object->context = $request->get('context');
$object->scope = $request->get('scope');
$authTokenResponse = Bigcommerce::getAuthToken($object);
Bigcommerce::configure(array(
'client_id' => 'xxxxxxxx',
'auth_token' => $authTokenResponse->access_token,
'store_hash' => 'xxxxxxx'
));
here the question is what is the $request variable? also, redirect_uri is the bigcommerce store URL or my site URL?
Please can anyone help to get started with this?
It's because that library is a bit out of date with how api accounts are managed. For the basic auth you would use "legacy accounts". You can just use the OAuth method without the oAuth flow (assuming you're trying to connect to your own store, not create an app).
Just the following will work:
Bigcommerce::configure(array(
'client_id' => 'client-id',
'auth_token' => 'access-token',
'store_hash' => 'store-hash'
));
You should get these after creating a user in the dashboard (you can ignore the secret for this use case)

Calling Google API from localhost

I am trying to call the Google CSE Api from my localhost Docker container. Apparently, this is not working because of that.
I have defined CURLOPT_SSL_VERIFYPEER to false in order to prevent SSL certificate verification, but with no success.
If anyone has any thought on this, help would be appreciated.
My code:
// Create the google api client
$googleClient = new Google_Client();
// Set the google developer api key
$googleClient->setApplicationName('GoogleApi_Search');
$googleClient->setDeveloperKey(self::GOOGLE_SEARCH_API_KEY);
// for development purposes
$guzzleConfig = [
'curl' => [CURLOPT_SSL_VERIFYPEER => false],
'headers' => ['Referer' => 'localhost:8080'],
];
$guzzleClient = new Client($guzzleConfig);
$googleClient->setHttpClient($guzzleClient);
// The google custom search service client
$this->googleService = new Google_Service_Customsearch($googleClient);
// Define the search parameters
$this->searchParams = [
'cx' => self::GOOGLE_SEARCH_ENGINE_ID, // Custom search engine identifier
'gl' => 'en', // Location of results
'lr' => 'lang_en', // Language of results
'num' => 10, // Number of results (max. 10)
'start' => 0, // The current index (max. 10)
];
I solved my issue by setting the start parameter to 1 instead of 0. Apparently, setting it to be 0 trigger a fatal error on the server side which causes the error 400 Invalid Value and no other information.
Strange but working.

Facebook PHP SDK V3 login token - Fatal error: Uncaught OAuthException:

The code below works fine with the PHP SDK v3. However, I had to use a java sdk login at first and now I don't know how to get a token with PHP or check if the user is logged in or not with PHP. I GET THE ERROR BELOW.
I can not use the SDK 4 yet as my hosting will not allow it. Long story. I have tried SEVERAL sites and tutorials for the past few hours to no avail. Can someone show me a simple way to do this? With code examples? What do I need to change the canvas url to on the Facebook app? etc..
Here is an error I get without the login.
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in
require 'Facebook3/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'myID',
'secret' => 'MySecret',
));
$attachment = array(
'message' => 'COOL',
'name' => 'Some Info',
'caption' => "more info",
'link' => 'http://aLink.com',
'description' => 'View Trailer Here!',
'picture' => 'http://Picture.com/images/aPic.png',
'actions' => array(
array(
'name' => 'Get Search',
'link' => 'http://www.google.com',
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);

How do I set report type for Amazon MWS report api

I have ordered this Transaction report from Amazon seller central because one can't request from Report's API.
Now I am trying to download this report using report api which is working fine, But now I am trying to set the report type to "_GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA_" so that I get requested report list for only this type of report.
I am using the code below but it's giving me this error
"Fatal error: Call to a member function getType() on a non-object in
/AmazonAPI/ReportsAPIClass/src/MarketplaceWebService/Client.php on
line 1605"
$config = array(
'ServiceURL' => $serviceURL,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
$AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $config, $APPLICATION_NAME, $APPLICATION_VERSION);
//===========================GETS REPORT ID
$request_report_list = new MarketplaceWebService_Model_GetReportListRequest();
$request_report_list->setMerchant($MERCHANT_ID);
$request_report_list->setAcknowledged(false);
$request_report_list->setMarketplace($MARKETPLACE_ID);
$request_report_list->setReportTypeList(array("TypeList" => "_GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA_"));
you have to create a class of type typelist and send as parameter
$TypeList = new MarketplaceWebService_Model_TypeList();
$TypeList->setType('_GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA_');
$request_report_list->setReportTypeList($TypeList);

How do I send json data using Zend 2 http?

I've been struggling with this for a few days now - I need to send a set of data encoded in json to an api. I'm trying to use Zend 2 http to achieve this but I've had no luck so far. Here is what the manual for the api says :
Bulk Create Contacts
This command can be used to insert new numbers into your Textlocal contact groups
and will allow you to insert extra fields such as the contact's name.
Parameter Description
group_id ID of the group you’d like to store the numbers in. This
contacts A JSON object containing all the details for each contact.
Note: It is recommended to send this request via POST.
Sample Request
(POST Variables):
username: testing#Textlocal.co.uk
hash: 4c0d2b951ffabd6f9a10489dc40fc356ec1d26d5
group_id: 5
contacts: [{"number":"447123456789","first_name":"Bob","last_name":"Smith","custom1":"","custom2":"","custom3":""},{"number":"447987654321","first_name":"Sally","last_name":"McKenzie","custom1":"","custom2":"","custom3":""},{"number":"447000000000","first_name":"Ramesh","last_name":"Dewani","custom1":"","custom2":"","custom3":""}]
Ok so that's what it expects and this is my code so far :-
include 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
use Zend\Http\Client;
use Zend\Http\Request;
$data = array(
'username' => 'myUsername',
'hash' => 'myHash',
'group_id' => 123456,
'contacts' => json_encode(array('number'=>447123456789,'first_name'=>'Bob','last_name'=>'Smith','custom1'=>"",'custom2'=>"","custom3"=>""))
);
$uri = 'https://api.txtlocal.com/create_contacts_bulk';
$request = new Request();
$request->setUri($uri);
$request->setMethod('POST');
$request->getPost()->set($data);
$config = array(
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'ssltransport' => 'ssl',
'sslcert' => '/etc/pki/tls/cert.pem',
'sslcapath' => '/etc/pki/tls/certs'
);
$client = new Client(null, $config);
$client->setEncType(Client::ENC_FORMDATA);
$response = $client->dispatch($request);
if ($response->isSuccess()) {
echo "the post worked!";
}else{
echo "the post failed";
}
That's not working and I'm sure there's I'm missing - here are the errors I get when I fire that script : -
[Thu Oct 24 09:29:47 2013] [error] [client] PHP Warning: Missing argument 2 for Zend\\Stdlib\\Parameters::set(), called in zend_test.php on line 24 and defined in Zend/Stdlib/Parameters.php on line 110
[Thu Oct 24 09:29:47 2013] [error] [client] PHP Notice: Undefined variable: value in Zend/Stdlib/Parameters.php on line 112
[Thu Oct 24 09:29:47 2013] [error] [client] PHP Fatal error: Uncaught exception 'Zend\\Http\\Client\\Exception\\RuntimeException' with message 'Cannot handle content type '' automatically' in Zend/Http/Client.php:1218\nStack trace:\n#0 Zend/Http/Client.php(858): Zend\\Http\\Client->prepareBody()\n#1 Zend/Http/Client.php(798): Zend\\Http\\Client->send(Object(Zend\\Http\\Request))\n#2 zend_test.php(30): Zend\\Http\\Client->dispatch(Object(Zend\\Http\\Request))\n#3 {main}\n thrown in Zend/Http/Client.php on line 1218
Any light you can shed or help you can give me would be greatly appreciated :)
Thanks in advance
Joe
You need to set the enc type when adding post data to the request object (this isn't very clear in the docs). Also, the example from the API manual implies that it's only the contacts that need to be JSON, you've encoded the whole array.
Try this:
$data = array(
'username' => 'myUsername',
'hash' => 'myHash',
'group_id' => 123456,
'contacts' => json_encode(array('number'=>447123456789,'first_name'=>'Bob','last_name'=>'Smith','custom1'=>"",'custom2'=>"","custom3"=>""))
);
$request = new Request();
$request->setUri('https://api.txtlocal.com/create_contacts_bulk');
$request->setMethod('POST');
$request->getPost()->fromArray($data);
$client = new Client();
$client->setEncType(Client::ENC_FORMDATA);
$response = $client->dispatch($request);
if ($response->isSuccess()) {
echo "the post worked!";
}else{
echo "the post failed";
}
Edit: In order to verify that the SSL certificate is valid, the HTTP client needs the path to the CA certificates on your web server.
You pass this in as a config option to the Http client instance:
$client = new Client(null, array(
'sslcapath' => '/etc/ssl/certs'
));
That's the path on Ubuntu, you'll need to find out what it is for your server.
By the way, instead of long constructions of Request, Response and Client classes please conider static Client usage:
http://framework.zend.com/manual/2.0/en/modules/zend.http.client-static.html
use Zend\Http\ClientStatic;
// Simple GET request
$response = ClientStatic::get('http://example.org');
// More complex GET request, specifying query string 'foo=bar' and adding a
// custom header to request JSON data be returned (Accept: application/json)
$response = ClientStatic::get(
'http://example.org',
array( 'foo' => 'bar' ),
array( 'Accept' => 'application/json')
);
// We can also do a POST request using the same format. Here we POST
// login credentials (username/password) to a login page:
$response = ClientStatic::post('https://example.org/login.php', array(
'username' => 'foo',
'password' => 'bar',
));

Categories