So, this morning I got the following error:
{"errors": [{"message": "The Twitter REST API v1 will soon stop functioning.
Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",
"code": 68}]}
Since I was using the tmhOauth twitter api I went to look if there are updates for it, and as it seems there is an issue listed here.
I'm using the api to update the status with media like this:
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
array(
'media[]' => "#{$image}",
'status' => "{$text}"
),
true, // use auth
true // multipart
);
I found notes that I should just change the link to use 1.1 instead of 1 but it's still not working.
My main problem was that I didn't read the docs fully! While the change in the url from 1 to 1.1 was sufficient I missed the point by not looking that the new url for update_with_media,
as explained in the documentation, is https://api.twitter.com/1.1/statuses/update_with_media.json, namely it's api instead of the old upload subdomain.
So, now my api call looks like this and all works again:
$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "#{$image}",
'status' => "{$text}"
),
true, // use auth
true // multipart
);
Hope this helps someone.
Instead of using tmhOauth api, use abraham's twitteroauth api ( updated to version 1.1 ) :
https://github.com/abraham/twitteroauth/tree/master/twitteroauth
and replace your code as follows :
$connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret, $twAccessToken, $twAccessTokenSecret);
$parameters = array(
'media[]' => "#{$image}",
'status' => "{$text}"
);
$code = $connection->post('statuses/update_with_media', $parameters);
Related
Forgive me for my ignorance, this is my first attempt at Drupal 8 and I'm not a good php developer to begin with. But I've been reading and searching for hours. I'm trying to do a post using the new Guzzle that replaces the drupal_http_request(). I've done this using Curl but can't seem to get this going in the right direction here. I'm just not "getting it".
Here is a sample of the array I have that pulls data from a custom form. I also tried this with a custom variable where I built the string.
$fields = array(
"enroll_id" => $plan,
"notice_date" => $date,
"effective_date" => $date,
);
$client = \Drupal::httpClient();
$response = $client->post('myCustomURL', ['query' => $fields]);
$data = $response->getBody()->getContents();
try {
drupal_set_message($data);
} catch (RequestException $e) {
watchdog_exception('MyCustomForm', $e->getMessage());
}
This indeed returns the result of REJECTED from my API in $data below - but it doesn't append the URL to included the query => array. I've tried numerous combinations of this just putting the fully built URL in the post (that works with my API - tested) and I still receive the same result from my API. In the end what I'm trying to accomplish is
https://myCustomURL?enroll_id=value¬ice_date=12/12/12&effective_date=12/12/12
Any direction or tips would be much appreciated.
Thanks for the responses guys. I was able to get it to work correctly by changing a few things in my post. First changing client -> post to a request('POST', XXX) and then changing "query" to "form_params" as "body" has been deprecated.
http://docs.guzzlephp.org/en/latest/quickstart.html#query-string-parameters
$client = \Drupal::httpClient();
$response = $client->request('POST','https://myURL.html', ['form_params' => $fields]);
$data = $response->getBody()->getContents();
Using $client->post will send a POST request. By looking at the URL that you tested directly you want a GET request.
Either use $client->get or $client->request with the GET parameter. More information and examples in the Guzzle documentation.
I used the Facebook PHP SDK to upload a YouTube Video in the FB user wall.
I used the "source" option in "/USER_ID/feed/" of Graph API.
USER_ID is the logged in user's Facebook ID.
My code was working fine.
But Facebook made some changes in their API and the code is not working anymore.
Only the Youtube video image is showing but the Youtube video is not playing in facebook.
My code looks like this:-
$params = array(
'access_token' => $fbToken,
'message' => $name.' has shared a Vhybe',
'link' => $link,
'name' => 'Vhybe Social',
'caption' => $title,
'description' => $content
);
$sourceUrl = "https://www.youtube.com/v/".$videoId;
$imageUrl = "http://i4.ytimg.com/vi/".$videoId."/default.jpg";
$params['source'] = $sourceUrl;
$params['picture'] = $imageUrl;
$result = $facebook->api(
'/'.$userId.'/feed/',
'POST',
$params
);
I tried the "Graph API explorer" tool from the Facebook developer tools section
URL => https://developers.facebook.com/tools/
But i am getting the same results.
If the above process to upload Youtube video to user wall has been deprecated can you please suggest me an alternate process.
Thanks in advance.
Sincerely,
Sourav Mukherjee
Well the above code is working fine again.
I did not make any changes in my code.
Looks like Facebook corrected their own issue.
Sincerely,
Sourav Mukherjee
I'm using the google-api-php-client to get the URL for a document on my Google Drive. The URL works correctly when I paste it into my browser and I can download the file.
However, in my PHP app I always get a 401. Here's my code:
private function _get_document_contents($url)
{
// prepare opts
$opts = array(
'http' => array(
'method' => 'GET',
'header' => "Gdata-version: 3.0\r\nAuthorization: Bearer " . $this->_token . "\r\n"
)
);
// get the doc
return file_get_contents($url . '&exportFormat=html&format=html', false, stream_context_create($opts));
}
I've tried changing Bearer to OAuth (that's what OAuth 2.0 playground uses) but both fail.
Any ideas?
Ah the problem seems to be that I'm using the old Google Docs API and should migrate over to the Google Drive SDK. D'oh!
I was trying to implement Twitter friendships/create by using REST Api 1.1 with PHP. But no matter how I tried it returns with
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => Bad Authentication data
[code] => 215
)
)
)
and my code is (using Abraham library and changed twitterauth to v1.1)
$twitteroauth = new TwitterOAuth( $this->consumer_key, $this->consumer_secret, $oauth_token, $oauth_token_secret);
$test_create = $twitteroauth->post('friendships/create',array('follow'=>true,'user_id'=>'2529416xx'));
print_r($test_create);exit;
I'm not an expert (I've got the same problem), but I think you shouldn't change the oauth version since it remains 1.0a. More information can be found here https://dev.twitter.com/docs/api/1.1/overview#Authentication_required_on_all_endpoints and here https://dev.twitter.com/docs/auth/authorizing-request
The change it's only in the URL of the request, for instance:
https://api.twitter.com/1.1/statuses/mentions_timeline.json
I was having the same problem like yours also. And the solutions are simple : dont change the version number (remains 1.0) and change the host to $host = "https://api.twitter.com/1.1/";
that solved mine!
You can try this code
Here your_screen_name you need to pass your screen_name and instead of your_user_id you need to pass your user id
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['token'] , $_SESSION['token_secret']);
$connection->post('friendships/create', array('screen_name'=>'your_screen_name','user_id'=>'your_user_id','follow'=>'true'));
I installed Zend Gdata 1.11.2 but I don't see anything in it labeled OAuth... does it support OAuth?
I do it like this, for Docs, Calendar, and Picasa:
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'signatureMethod' => 'HMAC-SHA1',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET
);
$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($oauthOptions,null);
$service = new Zend_Gdata_Photos($httpClient); //OR WHATEVER CLASS U WANT
...and then run your GData calls as normal through $service.
For OAuth there is seprate ZF component: Zend_OAuth.
No, it currently doesn't.
We integrate with a Google Documents for example, and all we can use currently is AuthSub. I haven't checked every line of code in there, but I think it's outdated in this respect. Of course we could create our own wrapper using OAuth, but this defeats the purpose of the framework for me.
Also, when you check out Google's examples, they tell you to use Zend_Oauth as well:
http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples (click on "PHP")
Oauth library is a part of the full ZF package.