I'm trying to make a call from PHP to the YouTube API v3 to get the duration of a video. I've got my developer key, and have assembled what seems to be a valid URL, based on Google's docs and many other posts on SO:
https://www.googleapis.com/youtube/v3/videos?id=rpVJkH7dWsY&part=contentDetails&key={myDeveloperKey}
I can enter this url into a browser, and a correct hunk of stuff comes back. But when I call it from PHP via file_get_contents($the_url), it fails with a "Connection timed out" error.
I must be doing something wrong; any advice? Thanks!
I'm doing it the exact same way you're describing, with file_get_contents($the_url), and it works fine for me. The only thing I can think of if it works in a browser but not on your server, is to make sure you're using a different API key that's a server key, where you'd be using a browser key to test from your browser, presumably. If that's not the issue, I can't think of any other obvious reason it shouldn't work.
Related
I'm trying to get the HTML source code of a SoundCloud link through PHP, but the https protocol makes it nearly impossible with file_get_contents(). I went with curl, but even though it does connect to SoundCloud, it returns a "track not found" error instead of the actual track page, so I suppose there's some additional protection.
Any help getting over this? I know there must be a way, since tools like http://source.domania.net/ have no trouble when I input an URL like https://soundcloud.com/mild-network/wcbf, for example.
Alternatively, is there any "page source viewer" online that can access https and has an API I could work with?
Hope this isn't too specific.
I'm using the LinkedIn api and would like to access companies but I'm running into a vague error that I haven't been able to figure out.
I'm using php and the php libracy 'Happyr\LinkedIn\LinkedIn' to access the API. My current application also has the 'rw_company_admin' permission attached to it.
When I make a call to the api endpoint '/v1/people/~:(id,first-name,last-name)', I get the correct response.
But when I make a call to the '/v1/companies?format=json&is-company-admin=true' endpoint I get the following error:
"Invalid company query request"
When I perform the exact same query in the LinkedIn Rest Console, I get the response I'm looking for. Any ideas?
Figured it out after hours of debugging.
The issue will probably be specific to the php package mentioned in the question. The LinkedIn library in use was automatically appending 'format=json' to the query call which sparked an error.
By removing the default output setting in the library, the call worked fine.
In my case, it was related to permissions of the application.
If you want to retrieve company list of the user, you should check rw_company_admin permission in the settings page of the application or give it to scope parameter. Then, you should get a new access token and make requests with it.
I've been using the Facebook php sdk to interact with facebook quite successfully. When I tried to create a photo album the code created a duplicate. At first I thought it was the php sdk (using 3.x). I tried switching to Perl with LWP::UserAgent and LWP::Simple::Post to use the http url for graph. Nothing is working. Every way I try I get double albums when I call the code. I've ensured that the code is being called once (mainly because I've created a super small test script to do it and have made outputs to ensure on the command line that it's only calling once.
Here's the url I'm using:
https://graph.facebook.com/me/albums?access_token=<access_token>&name=Test+Album+2&message=Test+Description
I've taken off the privacy setting from the url and it hasn't changed the behavior. If I run this directly in the graph explorer, it creates only one album. But any other method (yes, I am using POST and not GET and yes I've tried to pass all the params as post data individually rather than via querystring, either way results in duplicate albums) causes duplicate albums.
Has anyone experienced this? How do I fix it??? I'm at my wits end trying to figure this out.
I've tried it on multiple servers in thoughts that perhaps one of them was using a proxy causing the duplicate call, but whether I run it on my hosting service or on my localhost, I still get duplicates.
No matter what I've tried, if I am creating the album via code in PHP or Perl I get double albums created. HELP!
My first answer was deleted for some reason so I'm not sure what to do at this point. This question can't be answered because:
The issue was not with the SDK but with Facebook itself. I had created a bug report after doing some more tests. Facebook confirmed and fixed the bug. Basically, it had to do with inappropriate permissions handling.
https://developers.facebook.com/bugs/1435856773345641/
There was a bug in Facebook's handling in this instance. I'm hoping this answer doesn't get deleted because someone else may experience this and want to know that it was a bug in Facebook code, not in the PHP SDK or in the user code.
Not sure why Andrew Barber would delete that answer.
Unless someone has a better answer than what Facebook gave to me via bug report follow-up.
It seems Facebook is preventing search of a specific term.
As part of a site we are launching, had planned to query Facebook for the term #bestsummerever.
So the request to Graph API using an app access token for public data is the form:
/search/?q=%23bestsummerever
This now gives me the following error:
OAuthException
An unexpected error has occurred. Please retry your request later.
The error is new sometime between last week and this week.
I can query other "hashtags" with no issue, all of the following work:
/search/?q=%23bestsummereve
/search/?q=%23bestsummereverr
/search/?q=%23bestsummer
So it seems like I am strictly being prevented from querying #bestsummerever. This seems to be consistent regardless of what app I make the request with.
There does not seem to be any documented reason for this issue.
Can be reproduced using any app access token on the Facebook Graph Explorer. Really hoping this is some kind of small oversight on my part, but seems more like Facebook has some kind of restriction on that specific term.
First of all, Facebook requires that you provide an User Access Token if you search for obejcts other than places and pages (see https://developers.facebook.com/docs/graph-api/using-graph-api#search).
Apparently there IS some strange behaviour with your desired hashtag:
GET /search?q=%23selfie&type=post
works fine, whereas
GET /search?q=%23bestsummerever&type=post
produces an error. But
GET /search?q=bestsummerever&type=post
works for me. Strange, but maybe you can go on without the hashtag for now.
So a while back I used to use the twitter json search in one of my apps but it seems since the change in API versions there has been some major changes which even after reading the documentation I still can't get my head around and it really doesn't make it very easy to understand so hopefully one of you tech guys out there can help me out.
I want to clean my application up so it works again in plainly doing the following:-
http://search.twitter.com/search.json?
q='+param+'&
rpp=100&
result_type=recent&
lang=en
Obviously with the changes this is no longer possible but I want to be able to do this again using the new address but in JQuery unless someone can suggest either a tutorial or a piece of code or even a link to a topic where I could get my answer. I'm also open to using PHP as this is what I used at one point with searching Facebook's timeline and you can get an access token using $.get() for Facebook so surely it would be the same with Twitter too?
Any advice/code is welcome.
Thanks!
the search API needs authorization now. I'd say that, first off, you need to call the https url not http.
With Abhramam William's library you'd do something like the following, after having received your app's bearer token:
$your_tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=from:grey_mina&result_type=recent&count=5");