Youtube Video Upload in User Wall - youtube

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

Related

Twitter - Upload Image Using API and Get URL

I am creating a twitter share button that a user can click but I also want to attach an image to the tweet.
I am uploading the image to Twitter using the API so have the media ID available.
Is there a way to get the URL from this ID so I can attatch it to a Twitter Intent link?
Or can I only use this Media ID with the API to post a tweet for an authenticated user?
I am trying to attatch a Twitter hosted Image to a Share button so that anybody can post it to their Twitter feed
Before you can attach the image to a tweet, you would need to upload the image to twitter first. I think you are already doing this using the endpoint media/upload
Reference:
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
Once this is done issue another POST request to the endpoint statuses/update with parameters 'status' and 'media_ids'. Twitter expects a comma separated list of media_ids. You already have this in the object returned by media/upload endpoint.
Reference:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
The object returned in the above call has the url for each media uploaded under the property entities.
This is an excerpt from how I did using PHP and abrahamoauth library. $connection is the twitter connection object.
$media = $connection->upload('media/upload', array('media' => $_FILES["tweet_image_file"]["tmp_name"]));
$parameters = array(
'status' => '',
'media_ids' => implode(',', array($media->media_id_string)),
);
$result = $connection->post('statuses/update', $parameters);
//$image_url = $result->entities->media[0]->media_url; //stopped working from July 2015
$image_url = $result->entities->media[0]->url;

I can't get contentOwnerID on youtube API

I can't get contentOwnerID on youtube API.
$contentOwnersListResponse = $youtubePartner->contentOwners->listContentOwners(array('fetchMine' => true));
$contentOwnerId = $contentOwnersListResponse['items'][0]['id'];
this code can't get contentOwnerID. I'm using sample code from here [Uploading and Monetizing a Video
]1.
Why I can't get contentOwnerID? Please help me.

Tweeting an image using Twitter API

As a part of the application. I want users to share the image generated using the app with some text of their choice.
I went on to use a Twitter Library twitteroauth by natefanaro which supports to tweet images with text via Twitter API.
https://github.com/natefanaro/twitteroauth
According to the Library one can send a tweet with text by the method below.
$connection->post('statuses/update', array('status' =>"Test Tweet"));
When i tried with a post a tweet along with a image and text. It ain't works.Here's the code to post image with some text.
$connection->post('statuses/update_with_media', array('status' => 'Test Tweet with Img from App', 'media[]'=>'img03.jpg'));
PS: All i need is to let the users of the app share the image to their twitter timeline. Help me if there's a better method to do the same.
Change:
$connection->post('statuses/update_with_media', array('status' => 'Test Tweet with Img from App', 'media[]'=>'img03.jpg'));
to:
$connection->upload('statuses/update_with_media', array('status' => 'Test Tweet with Img from App', 'media[]'=>'img03.jpg'));
Notice the change from "post" to "upload"

tmhOauth twitter api stopped working with update_with_media call

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);

Using Koala, how can I attach an image when I publish to a user's stream?

I've started to play with the Koala gem for a RoR app. I've already got permission from the user to publish to their stream
After this line
graph = Koala::Facebook::GraphAPI.new(#facebook_cookies["access_token"])
to post to the stream, I can do a
graph.put_object("me", "feed", "I am writing to my wall")
The above works, but how do I include an image like http://example.com/foo.jpg as part of the update? I tried reading up the Stream Attachments but without a lot of luck. Does anyone have some sample code?
You can use something like:
options = {
:message => "I am writing to my wall",
:picture => "http://example.com/foo.jpg"
}
graph.put_object(facebook_uid, "feed", options)

Resources